实体框架排序包括 [英] Entity Framework Ordering Includes

查看:27
本文介绍了实体框架排序包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使以下内容起作用:

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();

导致异常的部分是:

.Include(x => x.Children.OrderBy(y => y.Order).ToList())

进一步观察,

_dbmsParentSections.ForEach(x => x.Children = x.Children.OrderBy(y => y.Order).ToList());

为我做了这项工作(在最初的 Factory 调用之后,没有 Children.OrderBy).

did the job for me (after the initial Factory call and without the Children.OrderBy).

推荐答案

您似乎无法对查询中的 children 集合进行排序.在查询后排序或在第二个查询中加载子项.

It seems you cannot sort the children collection in your query. Either sort after the query or load the children in a second query.

类似的问答这里

这篇关于实体框架排序包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆