Orchard CMS中的OrderByDescending

时间:2014-09-30 08:42:32

标签: orchardcms

我在Orchard CMS中遇到了OrderByDescending的问题

示例数据:

ID        Name             DomainId
1          First              2
2          Join               3
3          Peter              1
4          Abert              1
5          saha               2

使用LinQ to SQL代码:

  

IQueryable()。OrderByDescending(r => r.DomainId == 2)

它会返回正确的结果!

ID        Name             DomainId
1          First              2
5          saha               2
2          Join               3
3          Peter              1
4          Abert              1

,但使用OrchardCMS

  

IContentQuery()。OrderByDescending(r => r.DomainId == 2)

它返回不正确的结果,它将从大到小排序

ID        Name             DomainId
2          Join               3
1          First              2
5          saha               2
3          Peter              1
4          Abert              1

为何不正确?以及如何修复

请帮助我!


我想返回按DomainId排序的结果

示例:使用DomainId = 2 => IContentQuery()。OrderByDescending(r => r.DomainId == 2)

ID        Name             DomainId
1          First              2
5          saha               2
2          Join               3
3          Peter              1
4          Abert              1

示例:使用DomainId = 3 => IContentQuery()。OrderByDescending(r => r.DomainId == 3)

ID        Name             DomainId
2          Join               3
1          First              2
5          saha               2
3          Peter              1
4          Abert              1

2 个答案:

答案 0 :(得分:1)

尝试:     .OrderByDescending(r => r.DomainId == 2?1:0)

答案 1 :(得分:0)

我认为

IContentQuery().OrderByDescending(r=> r.DomainId)是正确的做法。表达式(r=> r.DomainId == 2)是否评估了正确的结果?