Home Articles

LINQ多个订单

Asked
Viewed 578 times
3

我有3个表小册子,分类和程序 . Pamphlet表具有CategoryID和ProgramID列 . 以下代码有效:

var pamphlets = db.Pamphlets.Include("Category").Include("Program").ToList();

我需要做的是按CategoryName(类别表)排序,然后按PamphletName(小册子表)排序 .

3 Answers

  • 7

    试试这个:

    var pamphlets = (from i in db.Pamphlets.Include("Category").Include("Program")
                     orderby i.Category.CategoryID, i.PamphletName
                     select i).ToList();
    
  • 1

    你只需将一个调用链接到ThenBy():

    var sortedPamphlets = db.Pamphlets.Include("Category").Include("Program")
                            .OrderBy(p => p.Category.CategoryName)
                            .ThenBy(p => p.PamphletName)
                            .ToList();
    
  • 1

    怎么样:

    var pamphlets = (from p in db.Pamphlets.Include("Category").Include("Program")
                    orderby p.Category.CategoryName, p.PamphletName
                    select p).ToList();
    

Related