LinQ Groupby Multiply Columns And Sum C#
i have a list of items in c# like this: Rid Pdv Total Quantity DESAYUNOS VITP 55 1 CENAS REST 38 2 COMIDAS VITP 23 3 DESAYUNO
Solution 1:
You should do it like this:
@foreach (var item in Model
.Select(x => new //here you count your total
{
Rid = x.Rid,
Total = x.Total * x.Quantity
})
.GroupBy(l => l.Rid) //and then grouping
.Select(z => new
{
Turno = z.Key,
Total = z.Sum(l => l.Total)
}))
{
<input value="@item" />
}
Solution 2:
I want to get a result in wich the Quantity is multiply by the Total and by that sum all totals for all diferent "Pdv" and "Rid"
@foreach (var item in Model
.Select(m => new { Rid = m.Rid, m.Pdv, Total =m.Total * m.Quantity})
.GroupBy(g => new { g.Rid, g.Pdv} )
.Select(s => new
{
Rid = s.Key.Rid,
Pdv = s.Key.Pdv,
Total = s.Sum(t => t.Total)
}))
{
<input value="@item" />
}
Post a Comment for "LinQ Groupby Multiply Columns And Sum C#"