How can I sort by multiple fields in LINQ?
how can I do multiple sort in
return (from p in _db.Pages where p.int_PostStatusId == 2 select p).OrderByDescending(m => m.int_SortOrder);
i want to do order by by int_PageId as 开发者_StackOverflow社区well? first by int_SortOrder then by int_PageId
Use either ThenBy
or ThenByDescending
to order the result of an OrderBy
or OrderByDescending
:
return (...)
.OrderByDescending(m => m.int_SortOrder)
.ThenBy(m => m.int_PageId);
Or using the query syntax:
orderby p.int_SortOrder descending, p.int_PageId
精彩评论