Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

linq - LINQ中的多个“order by”(Multiple “order by” in LINQ)

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

(我有两个表, moviescategories ,我首先按类别ID获取有序列表,然后按名称获取 。)

The movie table has three columns ID, Name and CategoryID .

(影片表有三列ID,Name和CategoryID 。)

The category table has two columns ID and Name .

(类别表有两列ID和名称 。)

I tried something like the following, but it didn't work.

(我尝试了类似下面的内容,但它没有用。)

var movies = _db.Movies.OrderBy( m => { m.CategoryID, m.Name })
  ask by Sasha translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

这应该适合你:

var movies = _db.Movies.OrderBy(c => c.Category).ThenBy(n => n.Name)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...