I'm trying to use this query using EF core:
entity.OrderBy(e => e.FieldOne.Sum(fo => fo.NestedField.Sum(nf => nf.SecondNestedField)));
Error:
Cannot perform an aggregate function on an expression containing an aggregate or a subquery. Cannot perform an aggregate function on an expression containing an aggregate or a subquery.
Is it possible to rewrite it EF core way?
CodePudding user response:
It's sound not possible to call a complex expression in Sum
. But you can flat the list and do a simple Sum
like :
entity.OrderBy(e.FieldOne.SelectMany(fo => fo.NestedField).Sum(nf => nf.SecondNestedField));