我正在尝试使以下内容起作用:
_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();
导致异常的部分是:
.Include(x => x.Children.OrderBy(y => y.Order).ToList())
编辑:
经过进一步观察,
_dbmsParentSections.ForEach(x => x.Children = x.Children.OrderBy(y => y.Order).ToList());
(在首次Factory致电后,没有Children.OrderBy)为我完成了这项工作。
Factory
Children.OrderBy
看来您无法对查询中的children集合进行排序。在查询之后进行排序,或者在第二个查询中加载子级。
类似的问题和答案在这里