开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜