实体框架排序导航对象
我有一个如下所示的查询
return this.Context.Modules
.Select(p => new
{
Module = p,
Page = p.Pages.OrderBy(c => c.AuthOrder)
}).ToList()
.Select(a => a.Module)
.ToList();
,但我正在使用 EF 4.2,我尝试像这样并通过 SQL Profiler 进行观察,EF 生成更多嵌套的 sql 查询,我只想对这项作业进行一个查询,这样
select * from Modules m join Pages p on m.ID = p.Module_ID
order by p.AuthOrder
怎么可能?
i have a query like below
return this.Context.Modules
.Select(p => new
{
Module = p,
Page = p.Pages.OrderBy(c => c.AuthOrder)
}).ToList()
.Select(a => a.Module)
.ToList();
but i am using EF 4.2 and i try like this and watching by SQL Profiler,EF generate much more sql queries its nested,i want to only one query for this job like this
select * from Modules m join Pages p on m.ID = p.Module_ID
order by p.AuthOrder
how is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这样的查询
可以通过以下方式实现:
Query like that
can be implemented next way:
您可能正在寻找
Include()
指定要包含在结果中的相关对象(即必须在 SQL 请求中连接哪些表):编辑:
您确定您的查询有意义吗?您实际上只选择了
Module
,那么为什么要尝试先订购Pages
呢?You probably are looking for
Include()
that specifies related object to include in your result (i.e. which tables must be joined in your SQL request):Edit:
Are you sure your query makes sense? You're actually only selecting
Module
, so why are you trying to orderPages
first?