Here is my code ,
db.myDBContext.my_tables.Where("REPLACE(LOWER(name),\" \",\"\") == \"{0}\"", value);
it show the error
No applicable method 'LOWER' exists in type 'my_table'
can't I use REPLACE
and LOWER
in dynamic linq clause ?
Dynamic Linq doesn't understand T-SQL. You will want to craft it this way:
.Where(string.Format("(name).ToLower().Replace(\" \", \"\") == \"{0}\" ", value))
There is an analog for ToLower
and Replace
in T-SQL and Linq knows how to translate them from c#.
But if name
is a static column name then @Jonny is on to something. You don't need Dynamic Linq here (unless this is just a contrived example of a bigger problem you are solving).