LINQ Multiple Order By
我有3个表小册子,类别和程序。 小册子表有一个CategoryID和ProgramID列。 以下代码工作:
var pamphlets = db.Pamphlets.Include("Category").Include("Program").ToList();
我需要做的是按CategoryName(类别表),然后是PamphletName(小册子表)。
您只需将一个调用链接到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/34273.html