MSDN does a really bad job at explaining nested groups in LINQ: https://learn.microsoft.com/en-us/dotnet/csharp/linq/create-a-nested-group
Take this example:
IEnumerable<IGrouping<Gender, IGrouping<Job, Person>>> query =
from person in peopleList
group person by person.Gender into genderGroup
from jobGroup (
from person in genderGroup
group person by person.Job
)
group jobGroup by genderGroup.Key;
My questions:
- In the from clause between parentheses, why does the source have to be genderGroup? Why can't it just be from peopleList like in the first from clause?
- In the last clause, which property of the jobGroup is actually being looked at when it is compared with genderGroup.Keys?