多个“由...排序"在LINQ [英] Multiple "order by" in LINQ
本文介绍了多个“由...排序"在LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个表movies
和categories
,我先按 categoryID 得到一个有序列表,然后按 Name 得到一个列表.
I have two tables, movies
and categories
, and I get an ordered list by categoryID first and then by Name.
电影表具有三列 ID,名称和类别ID . 类别表有两列 ID和Name .
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)
这篇关于多个“由...排序"在LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文