Contains
Ex1:
var uids = arrayofuids.Select(id => int.Parse(id)).ToList();
var selected = table.Where(t => uids.Contains(t.uid));
Ex2:
//用輸入的List ID 去DB找對應的ID
var dbItemSearchList = db.Item.Where(x => modelItemIDList.Contains(x.ID)).OrderBy(x => x.ID).ToList();
Except
//輸入5筆,DB有5筆,回傳True
bool hasMatch = ! modelList.Select(x => x.ItemID).Except(dbItemSearchList.Select(y => y.ID)).Any();
//輸入5筆,DB只有4筆,回傳沒有的那一筆資料
var dbItemSearchList = db.Item.Where(x => modelItemIDList.Contains(x.ID)).OrderBy(x => x.ID).ToList();
沒有留言:
張貼留言