[英]LINQ to check if ID exists in List
I am using LINQ Entity framework.我正在使用 LINQ 实体框架。 I have a SQL table and I want to get all the items in the table that have an ID that exist in a List
我有一个 SQL 表,我想获取表中具有列表中存在的 ID 的所有项目
Is this possible with LINQ?这可以用 LINQ 实现吗?
对的,这是可能的。
(from item in yourContext.YourTable where yourList.Contains(item.ID) select item).ToList();
为此,您可以用Contains
其转换成SQL IN
:
context.SomeTable.Where(r => someListOfId.Contains(r.ID));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.