简体   繁体   中英

LINQ to check if ID exists in List

I am using LINQ Entity framework. 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

Is this possible with 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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM