[英]LOWER and REPLACE doesn't work on dynamic linq where statement
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 ? 我不能在动态linq子句中使用
REPLACE
和LOWER
吗?
Dynamic Linq doesn't understand T-SQL. Dynamic Linq不了解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#. T-SQL中有一个
ToLower
和Replace
的类似物,Linq知道如何从c#转换它们。 But if name
is a static column name then @Jonny is on to something. 但是,如果
name
是静态列名,则@Jonny起作用。 You don't need Dynamic Linq here (unless this is just a contrived example of a bigger problem you are solving). 您在这里不需要Dynamic Linq(除非这只是您要解决的更大问题的人为例子)。
这样构建它怎么样?
Where(t=>t.name.toLower() == value)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.