我有下面的Linq,先按年,然后按月对列表进行分组。
var changesPerYearAndMonth = list
.GroupBy(revision => new { revision.LocalTimeStamp.Year, revision.LocalTimeStamp.Month })
.Select(group => new { GroupCriteria = group.Key, Count = group.Count() })
.OrderBy(x => x.GroupCriteria.Year)
.ThenBy(x => x.GroupCriteria.Month);
我的电流输出如下:
Year 2005, month 1, count 469
Year 2005, month 5, count 487
Year 2005, month 9, count 452
Year 2006, month 1, count 412
Year 2006, month 5, count 470
...
如您所见,查询中不包括没有值的月份。我想将它们包括在内,输出如下:
Year 2005, month 1, count 469
Year 2005, month 2, count 0
Year 2005, month 3, count 0
...
Year 2005, month 12, count 0
Year 2006, month 1, count 412
Year 2006, month 2, count 0
...
Year 2006, month 12, count 0
换言之,我也需要得到空月。
我可以用Linq查询实现这个功能吗?提前谢谢