Order results from RavenDB

I am using RavenDB and am running into problems when trying to order my results.

Here's a sample of the classes.

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

      

In my controller, I am trying to return a set of messages that are assigned to a specific section and then arrange (desc) the date portion of the Added property. Then I want to sort by SectionAssignment priority. Here's what I have:

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

      

I am the following exception:

Unable to launch object of type 'System.Linq.Expressions.MethodCallExpressionN' for input of type 'System.Linq.Expressions.MemberExpression'.

I understand why this is happening, but I cannot figure out how to do it. Any suggestions?

+3


source to share


1 answer


It is understood that it is the ThenBy clause that calls it.

If I recall correctly, the Ordering and Querying predicates cannot reference other fields - this is a Lucene limitation.



The interop is to instead set up a manual index that pulls the sort priority as a field, which you can then order.

+6


source







All Articles