Alan Alan - 5 months ago 11
C# Question

How can I order by more that one element with LINQ /

I have this LINQ statement:

db.PhraseCategories.OrderBy(c => c.Name);

I would like to order first by GroupId and then second by Name.

Can anyone give me advice on how I can do this?


You could use ThenBy extension method to performs a subsequent ordering of the elements in a sequence in ascending order according to a key.

.OrderBy(c => c.GroupId)
.ThenBy(c => c.Name);


from c in db.PhraseCategories         
orderby c.GroupId, c.Name