Multiple “order by” in LINQ

后端 未结 7 1625
小蘑菇
小蘑菇 2020-11-22 00:16

I have two tables, movies and categories, and I get an ordered list by categoryID first and then by Name.

相关标签:
7条回答
  • 2020-11-22 00:55

    Using non-lambda, query-syntax LINQ, you can do this:

    var movies = from row in _db.Movies 
                 orderby row.Category, row.Name
                 select row;
    

    [EDIT to address comment] To control the sort order, use the keywords ascending (which is the default and therefore not particularly useful) or descending, like so:

    var movies = from row in _db.Movies 
                 orderby row.Category descending, row.Name
                 select row;
    
    0 讨论(0)
提交回复
热议问题