I am using RavenDB and 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 Posts which is assigned to a specific Section, then order by (desc) the date portion of the Posted property. Then I want to to sort by the SectionAssignment Priority. Here's what I've got:
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 cast object of type 'System.Linq.Expressions.MethodCallExpressionN' to type 'System.Linq.Expressions.MemberExpression'.
I can see why this is happening, but I can't figure out how to make this work. Any suggestions?