Multiple “order by” in LINQ

后端 未结 7 1623
小蘑菇
小蘑菇 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:34

    Add "new":

    var movies = _db.Movies.OrderBy( m => new { m.CategoryID, m.Name })
    

    That works on my box. It does return something that can be used to sort. It returns an object with two values.

    Similar, but different to sorting by a combined column, as follows.

    var movies = _db.Movies.OrderBy( m => (m.CategoryID.ToString() + m.Name))
    

提交回复
热议问题