I have a problem with a Linq query. I have a query formatted like the following which returns a result set that is grouped by the top level and is ordered by the top level strings alphabetically. I want to return a result set that is ordered by both the top level strings (so the group by clause is ordered alphabetically) and the sub level strings are also in alphabetical order (so each sub group is also alphabetical). What I'm expecting is something like the following:
- A
- A
- B
- C
- B
- A
- B
- C
My query is something like the following:
records.results
.Where(table => string.Compare(table, expected) == 0)
.OrderByDescending(table => table.name)
.GroupBy(table => table.name);
.OrderBy(group => group.Key);
I expect the OrderByDescending statement to change the ordering of the individual records in the groupby clause but it isn't effecting anything. I am receiving ordered results for the groups though. Any help is appreciated!