如何在实体框架中预先加载子对象的子对象
我有一个 Member 类,它附加了一个 MemberRoles 数组。每个 MemberRoles 都附加有一个 Role 对象。当我去获取我的会员时,我知道我将需要与该会员关联的所有角色对象。我意识到我可以急切地加载 MemberRoles,
var member = context.Members.Include("MemberRoles").SingleOrDefault(....)
我在这里推测(因为我的 DBA 不会授予我运行探查器的权限,grumble *grumble*),但我假设与 MemberRole 对象关联的角色将一旦我开始访问它,就会延迟加载。
当我形成原始查询时,如何立即加载 Role 对象以及 MemberRoles?
I have a Member class that has an array of MemberRoles attached to it. Each of the MemberRoles have a Role object attached to them. When I go to fetch my Member I know that I am going to need all the Role objects associated to the Member. I realize that I can eager load the MemberRoles with
var member = context.Members.Include("MemberRoles").SingleOrDefault(....)
I am speculating here (because my DBA wont give me permission to run profiler, grumble *grumble*) but I assume that the Role associated to the MemberRole object will lazy load once I start accessing it.
How can I eager load the Role object along with the MemberRoles when I form my original query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
应该立即加载 MemberRoles 和关联的角色。
Try
That should eager-load MemberRoles and the associated Roles.