【问题标题】:multiple orderby in this linq code此 linq 代码中的多个 orderby
【发布时间】:2009-01-31 21:27:30
【问题描述】:

我如何添加第二个项目来订购? 我也想按goalsScored 元素排序。

var theteams = 
    (from teams in xdoc.Descendants("team")
     orderby (int)teams.Element("points") descending                               
     select 
         new Team(teams.Element("teamID").Value, 
                  (int)teams.Element("points"))                                
      ).Take(3);

但是 thenby 似乎没有插入到这个查询中。

【问题讨论】:

    标签: c# .net linq linq-to-xml


    【解决方案1】:
    var theteams =     
        (from teams in xdoc.Descendants("team")
        orderby (int)teams.Element("points") descending, OtherField1, OtherField2
        select new Team(teams.Element("teamID").Value,
        (int)teams.Element("points"))).Take(3);
    

    【讨论】:

      【解决方案2】:

      您可以通过用逗号分隔多个顺序子句来添加它们,例如

      orderby (int)teams.Element("points") descending, goalsScored
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-09-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多