我有一个列表(avgEnergyObj)
Timestamp | MeterID | Energy
----------------------------
190990001 | 1 | 98090.0
190990003 | 2 | 98909.3
190990002 | 2 | 99000.3
190990004 | 1 | 99900.9
我想按时间戳对其进行排序并按meterID分组,例如-
Timestamp | MeterID | Energy
----------------------------
190990001 | 1 | 98090.0
190990003 | 2 | 99000.3
190990002 | 1 | 98909.3
190990004 | 2 | 99900.9
我写了一些东西(不工作)一些错误 -
List<FetchingEnergy> avgEnergyObj2 =
avgEnergyObj.GroupBy(p => p.MeterId)
.Select(group =>
new {
meterID = group.Key,
FetchingEnergy = group.OrderBy(x => x.TimeStamp)
})
.OrderBy(group => group.FetchingEnergy.First().TimeStamp);