Jonathan Wood
Jonathan Wood

Reputation: 67283

Effect of OrderBy on Group-By Items

Given a query similar to the following:

var results = from x in context.Table
              orderby x.SortOrder
              group x by x.GroupColumn into g
              select g;

Is there any guarantee that items within each group will also be sorted by SortOrder?

Upvotes: 1

Views: 68

Answers (1)

brz
brz

Reputation: 6016

Yes, group by guarantees order of source IEnumerable. See this.

Elements in a grouping are yielded in the order that the elements that produced them appear in source.

Upvotes: 1

Related Questions