我有一个linq,它返回如下所示的值
我尝试了下面的代码来总结团队的关联点,
我希望获得关联积分和团队ID的总和
var result = from p in orderForBooks
group p by p.iTeamId into g
select new
{
points = g.Sum(x => x.Associate_Points),
teamid=g.Select(x=>x.iTeamId)
};
它总结了关联点,但未提取团队ID
答案 0 :(得分:2)
由于您按iTeamId
进行分组,因此您只需从群组iTeamId
获取每个群组Key
:
var result = from p in orderForBooks
group p by p.iTeamId into g
select new
{
points = g.Sum(x => x.Associate_Points),
teamid = g.Key
};
答案 1 :(得分:1)
var result = orderForBooks
.GroupBy(t => t.iTeamId )
.Select(tm => new ResultObj
{
teamid= tm.Key,
points = tm.Sum(c => c.Associate_Points)
}).ToList();