求linq语句 SELECT * FROM a
WHERE id NOT IN
(SELECT id FROM b)
LINQselectwhere
分享到:
------解决方案-------------------- from x in db.a
where !b.Select(y => y.id).Contains(x.id)
select x; ------解决方案-------------------- var query=a.Where(x=>!b.Select(y=>y.id).Contains(x.id)); ------解决方案--------------------
如果需要考虑效率且数据量比较大的话,建议你这样做:
var hs=new HashSet<int>(b.Select(y => y.id));
var query=a.Where(x=>!hs.Contains(x.id));