I am making use of System.Linq.Dynamic and for most of the time it works out great. However I'm trying to get a StartsWith
which would generate something like Description LIKE 'test%'
in T-SQL.
What I don't seem to find, and documentation is scarce as I noticed, is which statement to write in my code to pass to the Where method of the Dynamic library to generate that LIKE
statement.
Things I already tried but didn't work out for me:
.Where("Description LIKE \"test%\"");
.Where("Description < \"test%\"");
But nothing generates the LIKE statement I'm after.
System.Linq.Dynamic
translates your text to regular LINQ expressions, and there is no concept of "LIKE" there. How would you write your like in regular LINQ? Something like that:This maps almost exactly to what you should do with dynamic linq:
You can pass value inline too, though I'd recommend to always use parameters like above
You can replace
StartsWith
withContains
orEndsWith
to generate their respective tsql "LIKE" equivalents.