LINQ Multiple Order By
I have 3 tables Pamphlets, Categories and Program. The Pamphlet table has a CategoryID and ProgramID column. The following code works:
var pamphlets = db.Pamphlets.Include("Category").Include("Program").ToList();
What I need to do is sort by CategoryName (Category table) and then PamphletName (Pamphlet table).
您只需将一个调用链接到ThenBy():
var sortedPamphlets = db.Pamphlets.Include("Category").Include("Program")
.OrderBy(p => p.Category.CategoryName)
.ThenBy(p => p.PamphletName)
.ToList();
怎么样:
var pamphlets = (from p in db.Pamphlets.Include("Category").Include("Program")
orderby p.Category.CategoryName, p.PamphletName
select p).ToList();
尝试这个:
var pamphlets = (from i in db.Pamphlets.Include("Category").Include("Program")
orderby i.Category.CategoryID, i.PamphletName
select i).ToList();
链接地址: http://www.djcxy.com/p/34274.html
上一篇: 按照学说排列多列