2011-03-03 53 views
1

我有以下分組聲明:LINQ黨團由

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

基本上,查詢看起來在表中某一月內任命由天不計數月的每一天。 Daygroups將結果按天分組,以便我可以做日常計數。如何指定日期組內的日期?

謝謝。

回答

2

嘗試

where c.AppointDate < daygroups.Key 
0

你的日期是在daygroups.Key

當與LINQ分組,你在分組中的值IGrouping對象,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() 
}