开发者

How to eager load sub object of a sub object in Entities Framework

开发者 https://www.devze.com 2023-03-22 17:00 出处:网络
I 开发者_StackOverflowhave 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 goin

I 开发者_StackOverflowhave 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?


Try

var member = context.Members.Include("MemberRoles.Roles").SingleOrDefault(....)

That should eager-load MemberRoles and the associated Roles.

0

精彩评论

暂无评论...
验证码 换一张
取 消