开发者

Linq group by month

I have a table with a date field and time field.I want to retrieve a result set grouped by the month and the number of records that appear within that month. How can this be done in LINQ? Something like this.

Data.

10/10/2011 00:00:10:000

10/11/2011 00:00:20:000

11/01/2011 00:00:10:000

11/10/2011 00:00:40:000

I want to retrieve

10/1/2011 00:00:30:000

11/1/2011 00:00:50:000

Thank`s for help.

i am try something like this.

var monthely = 
  from u in sqlDataContract.TimeTrickTables 
  group u by u.EntryDate.Value.Month int开发者_运维技巧o g 
  select new 
  { 
    EntryDate = g.Key, 
    ETime = g.Aggregate(TimeSpan.Zero, (subtotal, t) => subtotal.Add((TimeSpan)t.ETime)) 
  };

but it throw this Exception The query operator 'Aggregate' is not supported


from u in TimeTrickTables
group u by u.EntryDate.Value.Month into g
select new
{
    Month = g.Key,
    Count = g.Count(), //Nr. of records
    Time = new TimeSpan(g.Sum(x => x.ETime.Ticks)) //Total time
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜