linq goup by day
I have the following grouping statement:
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)
}
Basically, the query looks in a table for appointments within a certain month and does counts by day for each day of the month. Daygroups groups the results by days so I can do the daily counts. How do I specify the date within the daygroups?
T开发者_开发百科hanks.
Try
where c.AppointDate < daygroups.Key
Your date is in daygroups.Key
When grouping with LINQ, the value you are grouping on ends up in the Key property of the IGrouping object, daygroups in your case.
Something like this, perhaps:
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()
}
精彩评论