Sql – linq2SQL + sum–Summing into results

linq-to-sql

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)

Best Answer

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) });
Related Topic