开发者

linq goup by day

开发者 https://www.devze.com 2023-02-15 03:52 出处:网络
I have the following grouping statement: var test = from a in MyDC.Table where ..... group a by a.Date into daygroups

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()
}
0

精彩评论

暂无评论...
验证码 换一张
取 消