1
2
3
4
5
6
7
8
9
10
11
12
13
|
var listTemp = from a
in
list
group a by
new
{ a.SectionCode } into g
orderby g.Key.SectionCode ascending
select
new
{
SectionCode = g.Key.SectionCode,
PitchTime = g.Sum(c => c.PitchTime),
MachineManPower = g.Sum(c => c.MachineManPower),
PMSum = g.Sum(c => c.MachineManPower * c.PitchTime)
};
|
1、需要引用 using System.Linq;
2、按多条件分组的时候 采取 new{a.ID,a.Name} 的形式
3、没有having 用上面两句代替
例二:object[] 中分组查询某字段 (虽然只有PalletID 一个字段 但是结果也是对象集合)
var palletGroupList = objs.GroupBy(m => new { ((MaterialConsumeQuery)m).PalletID }).Select(n => new { PalletID = n.Key.PalletID });