Linqpad C#表达分组子句

时间:2015-10-22 17:25:57

标签: c# linqpad

我有table

我希望使用Linqpad C#表达式使结果看起来像this table

但我无法按照上表中的DayOfWeek对数据进行分组。 这是我的代码:

 from s in Shifts
  where PlacementContractID == 3
  select new
 {
    DayOfWeek = s.DayOfWeek,
    EmployeesNeeded = s.NumberOfEmployees
 }

1 个答案:

答案 0 :(得分:2)

您似乎正在尝试执行以下操作:

Shifts.Where(sh => sh.PlacementContractID == 3)
      .GroupBy(sh => sh.DayOfWeek)
      .Select(g => new{ 
          DayOfWeek = g.Key, 
          EmployeesNeeded = g.Sum(sh => sh.NumberOfEmployees) //maybe a cast required?
      })

从查询语法转换为流利语法的道歉。