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?