問題描述
我一直在 google 上搜索,但沒有找到任何對我有用的東西.
I've been looking on google but not finding anything that does the trick for me.
如您所知,SQL 有一個where x in (1,2,3)"子句,它允許您檢查多個值.我正在使用 linq,但似乎找不到與上述語句相同的語法.
as you know SQL has a "where x in (1,2,3)" clause which allows you to check against multiple values. I'm using linq but I can't seem to find a piece of syntax that does the same as the above statement.
我有一個類別 ID(列表)的集合,我想根據這些集合進行檢查
I have a collection of category id's (List) against which I would like to check
我發現了一些使用 .contains 方法的東西,但它甚至沒有構建.
I found something that uses the .contains method but it doesn't even build.
推薦答案
你必須在你的 id 列表中使用 Contains 方法:
You have to use the Contains method on your id list:
var query = from t in db.Table
where idList.Contains(t.Id)
select t;
這篇關于LINQ Where in collection 子句的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!