[英]Linq: Totals Groups By Month
我有一個簡單的業務對象:
Crime
Date
PersonsInvolved
我需要一個每月總人數列表。 這些數據為1年,因此無需考慮。
Jan 5
Feb 3
Mar 5
等等
如果我有一個像這樣的內存集合,如何在Linq中完成:
List<Crime>() crimes;
crimes.GroupBy(c => c.Date.Month)
.Select(g => new { Month = g.Key, Count = g.Count() });
var q = from i in crimes
group i by i.Date.ToString("MMM") into grp
select new {Month = grp.Key, Count = grp.Sum(i => i.Persons)};
List<Crime>() crimes = ...
var crimesPerMonth = crimes.GroupBy(x => x.Date.Month);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.