In addition to a simple comma separated list of expressions (which is translated to ThenBy
method call), you can also specify the sorting order:
var q = from m in db.Movies
orderby m.Category descending, m.Name ascending
select m
// Translates to:
db.Movies.OrderByDescending(...).ThenBy(...)
Another example:
var q = from m in db.Movies
orderby m.Category, m.Name descending
select m
// Translates to:
db.Movies.OrderBy(...).ThenByDescending(...)
The first element of the comma separated list is translated to either OrderBy
or OrderByDescending
(if you specify the descending
keyword). Similarly, the next elements are translated to either ThenBy
or ThenByDescending
. You can also write ascending
, but this is the default option, so it behaves in exactly the same way as if you didn't use it.