I am trying to get something like the following to work:
_dbmsParentSections = FactoryTools.Factory.PdfSections .Include(x => x.Children.OrderBy(y => y.Order).ToList()) .Include(x => x.Hint).Include(x => x.Fields) .Where(x => x.FormId == FormId && x.Parent == null) .OrderBy(o => o.Order) .ToList();
The part that causes the exception is:
.Include(x => x.Children.OrderBy(y => y.Order).ToList())
EDIT:
Upon further observation,
_dbmsParentSections.ForEach(x => x.Children = x.Children.OrderBy(y => y.Order).ToList());
did the job for me (after the initial Factory
call and without the Children.OrderBy
).
It seems you cannot sort the children collection in your query. Either sort after the query or load the children in a second query.
Similar question and answer here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With