Reputation: 1
I've been trying to find an answer to my question but the wording is difficult.
Let say i have the following:
a first table of parties: party 1, party 2, party 3, party 4
a second table that records who belongs to what party:
party 1 - alex, party 1 - cynthia
party 2 - charles
party 3 - ana, party 3 - david
How could I build a linq query that would tell me how many people are going to each party, so the result would be:
party 1 , 2 people
party 2 , 1 people
party 3 , 2 people
Upvotes: 0
Views: 63
Reputation: 116108
list.GroupBy(x => x.Party)
.Select(x => new { Party = x.Key, Count = x.Count() });
Upvotes: 5