jonwagner / Insight.Database

Fast, lightweight .NET micro-ORM
Other
856 stars 145 forks source link

How can i specify data type for sql query? #512

Closed rscx-r1 closed 2 months ago

rscx-r1 commented 3 months ago

Hello, i have this code:

[Sql("SELECT * FROM lines WHERE CONTAINS(url, @url)")] Task<IList<LinesDB>> SelectLinesByUrl(string url);

With this code i cant use a CONTAINS predicate because Insight interpretes a nvarchar(MAX) automatically, how can i specify for example varchar(1500) (as in my database)?

jonwagner commented 3 months ago

Hm...sql text doesn't give us enough information to detect the type.

We might be able to add parameter annotations like @url:varchar(1500). Let me think about how we can do that without breaking existing code.

rscx-r1 commented 3 months ago

Looks great, but i need solve a problem today, did you have any ideas? project already based on your orm. =c

jonwagner commented 3 months ago
rscx-r1 commented 3 months ago

Incorrect syntax around the "CONVERT" keyword.

SELECT * FROM lines WHERE CONTAINS(url, CONVERT(varchar(1500), @url))

jonwagner commented 3 months ago

interesting. didn't know you can't use a function in the contains parameter list.

You might be able to declare a variable and convert with that:

DECLARE @u varchar(1500)
SELECT @u = @url
select * from url where CONTAINS (url, @u)
rscx-r1 commented 3 months ago

nah, that's not working too, Invalid object name "url". i think @url:varchar(1500) is the better idea, i solved it by temporarily by selfmade function but i will wait this update, and please add net7.0 support, thank you!

jonwagner commented 2 months ago

in v8.0.1 I added support for type tags in sqltext.

e.g.

[Sql("SELECT FROM lines WHERE CONTAINS(url, / TYPE: string(1500)" */ @url)")]

I probably should have done this a while ago.

LMK how it works for you.