Linq to sql translation to sql of custom method

Posted by DJPB on Stack Overflow See other posts from Stack Overflow or by DJPB
Published on 2010-03-18T16:43:46Z Indexed on 2010/03/18 16:51 UTC
Read the original article Hit count: 377

Filed under:
|

hi there

is there a way to translate an expression to sql to use with linq to sql?

for example I have a method that compares two values

example:

MyComparer.Compare(value1, value2, ">") return value1 > value2
MyComparer.Compare(value1, value2, "=") return value1 == value2
MyComparer.Compare(value1, value2, "<=") return value1 <= value2

and i would like a query like

var list = from i in dataContext.items
           where MyComparer.Compare(i.value, someValue, "some operator")
           select ...

this won't work because, obviously, MyComparer doesn't translate to sql

maybe this is a twisted question, but how can i translate this method to sql or is this possible?

tks

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about c#