我已经在LINQPad中测试了以下查询,它运行良好,但是VS2010不喜欢它。
var topJobs = from j in streetlightDBEntities.Job
let mjobid = from m in streetlightDBEntities.Job.Include("Streetlight")
where m.Streetlight.StreetlightId == j.Streetlight.StreetlightId
orderby m.DateCompleted descending
select m.JobId
where mjobid.Take(5).Contains(j.JobId)
select j.JobId;
var notTopJobs = streetlightDBEntities.Job.Where(c => !topJobs.Contains(c.JobId));
我收到以下错误:
最佳答案
使用Queryable.Any <TSource>
。
代替这个:
var notTopJobs = streetlightDBEntities
.Job
.Where(c => !topJobs.Contains(c.JobId));
做这个:
var notTopJobs = streetlightDBEntities
.Job
.Where(c => !topJobs.Any(x => x.JobId == c.JobId))
对原始查询执行相同的操作。
关于c# - Linq查询中的'IN'和 'NOT IN',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4301023/