You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 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 territoryByPerson
select new
{
SalesTerritory = territoryByPerson.Key,
TotalBonus = territoryByPerson.Sum(person => person.Bonus)
};
B.
from territory in model.SalesTerritories
group territory by territory.SalesPerson
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);
The answer is correct, but dummies at microsoft switched names (should be personByTerritory in A, and territoryByPerson in B). If it was anyone else, I’d figure they want to confuse the test-takers, but in this case it’s just pure incompetence.