Linq RavenDB的排序结果

Linq RavenDB的排序结果,linq,ravendb,Linq,Ravendb,我正在使用RavenDB,在尝试排序结果时遇到了问题 这是一个类的示例 public class Post { public int Id {get;get;} public DateTimeOffset Posted {get;set;} public List<SectionAssignment> Sections{get;set;} public string Headline {get;set;} } public class SectionA

我正在使用RavenDB,在尝试排序结果时遇到了问题

这是一个类的示例

public class Post {
    public int Id {get;get;}
    public DateTimeOffset Posted {get;set;}
    public List<SectionAssignment> Sections{get;set;}
    public string Headline {get;set;}
}
public class SectionAssignment {
    public int SectionId {get;set;}
    public int Priority {get;set;}
}
公共类职位{
公共int Id{get;get;}
public DateTimeOffset Posted{get;set;}
公共列表节{get;set;}
公共字符串标题{get;set;}
}
公开课分配{
public int SectionId{get;set;}
公共int优先级{get;set;}
}
在我的控制器中,我试图返回一组分配给特定部分的帖子,然后按(desc)发布属性的日期部分排序。然后我想按分区分配优先级排序。以下是我得到的:

var posts= RavenSession.Query<Post>()
    .Where(s => s.Sections.Any(sec=>sec.SectionId==5))
    .OrderByDescending(s => s.Posted.Date)
    .ThenBy(s => s.Section.Where(sec => sec.Id == 5).Select(sc => sc.Priority).Single())
    .Take(10)
    .ToList();
var posts=RavenSession.Query()
.其中(s=>s.Sections.Any(sec=>sec.SectionId==5))
.OrderByDescending(s=>s.Posted.Date)
.ThenBy(s=>s.Section.Where(sec=>sec.Id==5)。选择(sc=>sc.Priority.Single())
.Take(10)
.ToList();
我是以下例外:

无法强制转换类型为的对象 “System.Linq.Expressions.MethodCallExpressionN”以键入 'System.Linq.Expressions.MemberExpression'

我能理解为什么会发生这种情况,但我不知道如何让它起作用。
有什么建议吗?

一个有根据的猜测是,是你的ThenBy子句导致了它的失败

如果我没记错的话,排序和查询谓词不能引用其他字段——这是Lucene的一个限制

一种解决方法是设置一个手动索引,将排序优先级作为字段提取出来,然后您可以根据该字段进行排序