0

am using specification pattern (1) with EF Core 3.1.7. I generate an IQueryable object then I want to apply the specification for my use cases.

IQueryable builder method (Base specification method AddInclude) :

query = specification.Includes.Aggregate(query,
  (current, include) => current.Include(include));

When I use Include method, it works correctly.

But I need to add custom include conditions. For example:

private void IncludePrice()
{
   AddInclude(x => x.Prices.OrderByDescending(x => x.CreationDate));
}

EF Core does not generate queries with this lambda expression. It throws:

Lambda expression used inside Include is not valid.

How can I solve this?

pinkfloydx33
  • 11,863
  • 3
  • 46
  • 63
Sumit Roy
  • 13
  • 1
  • 4

0 Answers0