日期:2014-05-17  浏览次数:20447 次

linq 中怎么表达 SQL中的 not in
select * from stuInfo where stuNo not in(select stuNo from StuMarks)
怎么用 Linq 进行书写。 求解谢谢!


------解决方案--------------------
all的写法:
var query = db.stuInfo.Where(x => db.StuMarks.All(y => y.stuNo != x.stuNo));

join的写法

C# code
var query = from x in db.stuInfo
            join y in db.StuMarks on x.stuNo equals y.stuNo into j
            from item in j.DefaultIfEmpty(default(StuMark类型))
            where item == default(StuMark类型)
            select x;