我有以下分组声明:
var test = from a in MyDC.Table
where .....
group a by a.Date into daygroups
select new MyModel()
{
TheCount = (from c in daygroups
where c.AppointDate < "the date of the daygroups for this day").Sum( d =>d)
}
基本上,查询在表格中查找某个月内的约会,并按月计算每月的每一天。日期组将结果按天分组,以便我可以进行每日计数。如何在日期组中指定日期?
感谢。
答案 0 :(得分:2)
尝试
where c.AppointDate < daygroups.Key
答案 1 :(得分:0)
您的约会对象是daygroups.Key
使用LINQ进行分组时,您分组的值最终会出现在IGrouping对象的Key属性中,例如,在您的情况下为daygroups。
这样的事情,也许是:
var test = from a in MyDC.Table
where .....
group a by a.Date into daygroups
select new MyModel {
TheCount = daygroups.Where(d => d.AppointDate < daygroups.Key).Count()
}