var expr = Data.Customers
.GroupBy(c => c.Country, c => c.Name);
foreach (IGrouping<Countries, string> customerGroup in expr)
{
Trace.WriteLine("Country: " + customerGroup.Key);
foreach (var item in customerGroup)
{
Trace.WriteLine(item);
}
Trace.WriteLine("");
}
I wish I got following result:
Country: Italy
Paolo
Marco
Country: USA
James
Frank
instead of:
Country: Italy
Paolo
Marco
Country: USA
James
Frank
Frank
If it is possible, please make it using standard LINQ syntax.
If you want to group by multiple keys you have to use an anonymous type:
Then you can access
expr.Key.Countryandexpr.Key.Name.