这是我的结构:
程序 - 描述等......
动作 - Program_Id,Description等。
费用 - Action_Id,Value1,Value2,Value3
一个操作可以有多个费用。 我需要的是一个通过Program对这个值进行分组的查询。像:
“程序名称”|总价值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 = ?
};
答案 0 :(得分:2)
这样的事情有用吗?
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)
};