如何在一个LINQ上获得children值的总和
本文关键字:children LINQ 一个 | 更新日期: 2023-09-27 18:24:51
这是我的结构:
程序-描述等…
操作-程序Id、说明等。
成本-Action_Id、Value1、Value2、Value3
一个操作可以有多个成本。我需要的是一个按程序对这些值进行分组的查询。类似:
"程序名称"|总值1 |总值2 |程序总额
这是我迄今为止的努力:
var ListByPrograma = from a in db.Actions
join c in db.Costs on a.Id equals c.Action_Id
group a by a.Program into p
select new
{
Program = p.Key,
actionsQuantity = p.Count(),
totalValue1 = p.Costs.????
totalValue2 = ?,
totalByProgram = ?
};
这样的东西行得通吗?
var ListByPrograma = from a in db.Actions
join c in db.Costs on a.ID equals c.Action_Id
group new {a,c} by a.Program into p
select new
{
Program = p.Key,
actionsQty = p.Count ( ),
totalValue1 = p.Sum(y => y.c.Value1),
totalValue2 = p.Sum (y => y.c.Value2),
totalValue3 = p.Sum(y=>y.c.Value3)
};