在Lambda表达式中使用Group By Having

时间:2014-06-30 12:47:30

标签: c# linq

任何人都可以帮我将下面的查询转换为LINQ with Lambda expression。

select idshiftschedule,Date from Teammateassignments 
where IdClinic = 19
group by IdshiftSchedule,DATE having COUNT(Date)>1

1 个答案:

答案 0 :(得分:1)

这只是后来群组的过滤器:

 var results = from item in assignments
               where item.IdClient == 19
               group item by new { item.IdShiftSchedule, item.Date } into g
               where g.Count() > 1
               select g.Key;

(我假设Count(Date) > 1实际上只是在计算组中的项目数...例如,如果Date可以为空,我不清楚它会做什么。)