jeanres
jeanres

Reputation:

linq2SQL + sum--Summing into results

I have a bunch of incidences in a table that are linked to a supplier

I need to sum the serverity score for those incidences by supplier

So basicly have supplier1: 500 supplier2: 600

How do I do this?

DataAccess.IncidentRepository().GetItems().Where(i => i.IncidentDate.Year == 2006)

Upvotes: 0

Views: 152

Answers (1)

Vasu Balakrishnan
Vasu Balakrishnan

Reputation: 1771

Hope this helps

DataAccess.IncidentRepository().GetItems()
          .Where(i => i.IncidentDate.Year == 2006)
          .GroupBy(i => i.Supplier)
          .Select(pGroup => 
                  new { Supplier = pGroup.Key, 
                        Score = pGroup.Sum(pArg => pArg.SeverityScore) });

Upvotes: 1

Related Questions