jody jody - 7 months ago 50
SQL Question

how to convert from sql query to linq

I am new to linq, how to convert the following sql query to linq

SELECT WorkingHoursID
FROM WorkingHours
SELECT WorkingHoursID
FROM Schedule
WHERE Date = '2016-08-25'
GROUP BY WorkingHoursID
HAVING COUNT( WorkingHoursID ) >= 8


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);