To use multiple order by statements in your LINQ query you can use the OrderBy Method combined with multiple ThenBy Method’s.
so let’s create a sample class
and fill a List of Track with Track items
the items are printed without sorting in the following order
now let’s sort the List of Tracks first by AlbumId Ascending and ThenBy Title Descending.
var sortedTracksQuerySyntax = (from track in tracks orderby track.AlbumId ascending, track.Title descending select track); var sortedTracksAggregateFunctions = tracks.OrderBy(track => track.AlbumId).ThenByDescending(track => track.Title);
which will produce the following result
you can use as much ThenBy Statements as you need, example:
var sortedTracksAggregateFunctions = tracks.OrderBy(track => track.AlbumId).ThenByDescending(track => track.Title).ThenBy(track => track.AlbumTitle).ThenByDescending(track => track.Length).ThenBy(track => track.Year);
more informations can be found at the MSDN OrderBy Method, ThenBy Method’s, LINQ, 101 LINQ Samples