You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to develop an application
that uses the Entity Framework. The application has an entity model that includes SalesTerritory and
SalesPerson entities as shown in the following diagram.
You need to calculate the total bonus for all sales people in each sales territory. Which code segment
should you use?
A.
from person in model.SalesPersons
group person by person.SalesTerritory
into territoriesByPerson
select new
{
SalesTerritory = territoriesByPerson.Key,
TotalBonus = territoriesByPerson.Sum(person => person.Bonus)
};
B.
from territory in model.SalesTerritories
group territory by territory.SalesPersons
into personByterritories
select new
{
SalesTerritory = personByterritories.Key,
TotalBonus = personByterritories.Key.Sum(person => person.Bonus)
};
C.
model.SalesPersons
.GroupBy(person => person.SalesTerritory)
.SelectMany(group => group.Key.SalesPersons)
.Sum(person => person.Bonus);
D.
model.SalesTerritories
.GroupBy(territory => territory.SalesPersons)
.SelectMany(group => group.Key)
.Sum(person => person.Bonus);