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).
这样构建它怎么样?
Where(t=>t.name.toLower() == value)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.