linq中或包含? [英] linq in or contains?
本文介绍了linq中或包含?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Linq-to-sql进行这样的搜索:
How can I use Linq-to-sql to a search like this:
其中obj.id等于以下{1,2,3,4}
where obj.id equals any of the following {1,2,3,4}
我想我可以使用in或包含吗?
I would guess I could use the in or perhaps contains?
其中Enumerable.Range((int)myEnum.Start,(int)myEnum.End))中的obj.id吗?
where obj.id in Enumerable.Range( (int) myEnum.Start, (int) myEnum.End) ) ?
推荐答案
您可以使用 .Contains()
,如下所示:
You can use .Contains()
, like this:
var list = new List<int> { 1, 2, 3, 5 };
var result = from s in DB.Something
where list.Contains(s.Id)
select s;
这将被转换为以下参数化形式:
This will get translated to a parameterized form of:
WHERE Id IN (1, 2, 3, 5)
这篇关于linq中或包含?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文