多个排序依据本LINQ code [英] multiple orderby in this linq code

查看:107
本文介绍了多个排序依据本LINQ code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何加入到这样的顺序由第二个项目? 我想通过一个goalsScored元订购了。

  VAR theteams =
    (从团队xdoc.Descendants(小组)
     排序依据(INT)teams.Element(分)降
     选择
         新的团队(teams.Element(teamID),价值,
                  (INT)teams.Element(分))
      )。取(3);
 

但thenby似乎并不插槽来此查询。

解决方案

  VAR theteams =
    (从团队xdoc.Descendants(小组)
    排序依据(INT)teams.Element(分)递减,Ot​​herField1,OtherField2
    选择新的团队(teams.Element(teamID),价值,
    (INT)teams.Element(分)))以(3);
 

How do I add a second item to order by with this? I want to order by a goalsScored element too.

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);

but thenby doesn't seem to slot in to this query.

解决方案

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);

这篇关于多个排序依据本LINQ code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆