1)group by 只对单一参数分组:
from d in _dbContext.table
where type = 1
group d by new { d.CreateTime.Hour} into g
select new UseGasDistribute
{
HourTime = g.Key,
ActuallyUse = g.Sum(t => t.MonitorValue)
}
2)group by 对多个参数分组:
from d in _dbContext.table
where type = 1
group d by new { d.CreateTime.Hour,d.Code} into g
select new UseGasDistribute
{
HourTime = g.Key,
ActuallyUse = g.Sum(t => t.MonitorValue)
}
结果为:
{
"hourTime": { Hour = 8, Code = GH506L_BKSSLL },
"actuallyUse": 3093.16309
}
hourTime变为对象,对象内容为 group by 内容