大家好我有以下代码
var deptSalesQuery = from d in db.DashboardFigures
join s in outlets.Split(',').Select(x => int.Parse(x)) on d.OutletNo equals s
where (d.TypeOfinformation == "DEPTSALES")
select new DeptSales
{
Dn = (int)d.Number,
On = d.OutletNo,
Qs = (double)d.Value_4,
Se = (double)d.Value_2,
Si = (double)d.Value_3
};
我想要做的是将查询分组为“Dn'这是' d.Number'并返回 (double)d.Value_4,(double)d.Value_2,(double)d.Value_3之和。我看过论坛,有些人问过类似的问题,但由于某些原因,它不适合我。有人可以帮忙吗?
我已将代码更改为
var deptSalesQuery = from d in db.DashboardFigures
join s in outlets.Split(',').Select(x => int.Parse(x)) on d.OutletNo equals s
where (d.TypeOfinformation == "DEPTSALES")
group d by d.Number into newGroupedresult
select new DeptSales
{
Qs = (double)newGroupedresult.Sum(d => d.Value_4),
Se = (double)newGroupedresult.Sum(d => d.Value_2),
Si = (double)newGroupedresult.Sum(d => d.Value_3)
};
但它没有分组,它显示了个人记录。我通常也有Dn = D.Number,它不允许我把它。
答案 0 :(得分:0)
deptSalesQuery
.GroupBy(x => x.Number)
.Select(g => new
{
Dn = g.Key,
Sum = g.Sum(x => x.Value_2 + x.Value_3 + Value_4)
});