[英]Linq to SQL “not like” operator
I have a simple SQL statement. 我有一个简单的SQL语句。
Select distinct value from tablename where value not like '%TEST%' 从tablename中选择不同的值,其值不像'%TEST%'
How do I write this in Linq to SQL syntax. 我如何用Linq to SQL语法编写它。
I tried the below statement but it doesnt seem to work. 我尝试了以下声明,但它似乎没有奏效。
var p = (from c in tablename where !(c.value.ToUpper().Contains("%TEST%"))
select c.Value).Distinct().ToList()
The problem is the "%" - you're looking for things which literally don't contain "%TEST%" which would probably be everything. 问题是“%” - 你正在寻找的东西实际上并不包含“%TEST%”,这可能就是一切。 I think you mean: 我想你的意思是:
var p = (from c in tablename
where !c.Value.ToUpper().Contains("TEST")
select c.Value).Distinct().ToList()
If you were stuck with a pattern for sql to match, you could use SqlMethods.Like 如果你遇到了匹配sql的模式,你可以使用SqlMethods.Like
string pattern = "%TEST%";
...
from c in tablename
where !SqlMethods.Like(c.Value, pattern)
select c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.