2015-01-16 19 views
2

措辭可憐我知道,所以我很清楚這裏..LINQ的選擇很多,其中樓盤X存在於externalList

List<int> relevantIDs; //self explanitory 

現在我想請從對象列表數據庫所在的列表中存在其ID上面......我似乎無法找出LINQ ...

dbContext.objs.where(x => x.id ....).toList(); 
//I cant figure out the .... i was thinking there was an "in" but got no where... 

可有人點我的文章或提供給我一個樣品,將完成我需要什麼。該列表將太大,只是檢索它們,然後過濾下來....重複擊中數據庫在這種情況下將不是最佳...

回答

6

你想從數據庫中找到包含的ID 你的「相關標識」的集合,所以這應該工作:

dbContext.objs.Where(x => relevantIDs.Contains(x.id)).ToList(); 
4

您正在尋找Contains

dbContext.objs.Where(x => relevantIDs.Contains(x.id)).ToList(); 

這將轉換爲IN條款爲SQL