Reputation: 31
I am new to linq, how to convert the following sql query to linq
SELECT WorkingHoursID
FROM WorkingHours
except
(
SELECT WorkingHoursID
FROM Schedule
WHERE Date = '2016-08-25'
GROUP BY WorkingHoursID
HAVING COUNT( WorkingHoursID ) >= 8
)
Upvotes: 2
Views: 61
Reputation: 37299
Using the Except
method, you can do something like this:
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);
Upvotes: 2