多个“order by"在 LINQ [英] Multiple "order by" in LINQ
本文介绍了多个“order by"在 LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个表,movies
和 categories
,我想先按 categoryID 再按 获取有序列表姓名.
I have two tables, movies
and categories
, and I want to get an ordered list by categoryID first and then by Name.
电影表有三列ID、Name 和 CategoryID.类别表有两列ID 和名称.
The movie table has three columns ID, Name and CategoryID. The category table has two columns ID and Name.
我尝试了类似以下的方法,但没有奏效.
I tried something like the following, but it didn't work.
var movies = _db.Movies.OrderBy( m => { m.CategoryID, m.Name })
推荐答案
这应该适合你:
var movies = _db.Movies.OrderBy(c => c.Category).ThenBy(n => n.Name)
这篇关于多个“order by"在 LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文