我是linq的新手,如何将以下sql查询转换为linq
SELECT WorkingHoursID
FROM WorkingHours
except
(
SELECT WorkingHoursID
FROM Schedule
WHERE Date = '2016-08-25'
GROUP BY WorkingHoursID
HAVING COUNT( WorkingHoursID ) >= 8
)
答案 0 :(得分:2)
使用Except
方法,您可以执行以下操作:
var schedules = (from s in DBCon.Schedule
where s.Date == new DateTime(2016, 8, 25)
group s by s.WorkingHoursID into g
where g.Count() >= 8
select g.Key).ToList();
var result = DBCon.WorkingHours.Select(item => item.WorkingHoursID).Except(schedules);