常常统计时会需要按年月统计。
var data = from ds in query
group ds by new
{
Month = ds.CreateDate != null ? ds.CreateDate.Month : 8,
Year = ds.CreateDate != null ? ds.CreateDate.Year : 2013
}
into gp
let item = gp.FirstOrDefault()
select new
{
Year = item.CreateDate.Year,
Month = item.CreateDate.Month,
Count = gp.Count()
};