使用linq时,我必须检查数组中是否存在行的值。
相当于sql查询:
WHERE ID IN (2,3,4,5)
我该怎么做呢?
发布于 2010-02-25 21:45:41
.Contains
var resultset = from x in collection where new[] {2,3,4,5}.Contains(x) select x
当然,对于你的简单问题,你可能会有这样的结果:
var resultset = from x in collection where x >= 2 && x <= 5 select x
发布于 2010-02-25 21:48:32
使用IEnumerable.Contains()执行等同于SQL的操作。
var idlist = new int[] { 2, 3, 4, 5 };
var result = from x in source
where idlist.Contains(x.Id)
select x;
发布于 2010-02-25 21:47:26
db.SomeTable.Where(x => new[] {2,3,4,5}.Contains(x));
或
from x in db.SomeTable
where new[] {2,3,4,5}.Contains(x)
https://stackoverflow.com/questions/2334327
复制相似问题