Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 31, 2013 09:52 AM by billcrawley
Member
341 Points
286 Posts
Jan 31, 2013 09:38 AM|LINK
Hi all,
I have an appointment object linked to a contact object linked to a contact type object.
I can perform an eager-load on the appointment object to contact object with :
using (EnvoyModelContainer ctx = new EnvoyModelContainer()) { return ctx.Appointments.Include("Contact").ToList(); }
and this will return my records.
howver, because ther is no direct relationship between appointment and contact type I cannot do this:
using (EnvoyModelContainer ctx = new EnvoyModelContainer()) { return ctx.Appointments.Include("Contact").Include("ContactTypes").ToList(); }
What should I do to return my chained objects?
All-Star
86809 Points
9646 Posts
Moderator
MVP
Jan 31, 2013 09:46 AM|LINK
Unfortunately you can't daisy chain Includes because of how those work. You can make it work like this:
ctx.Appointments.Include("Contact.ContactTypes").ToList();
You can see more on loading related entities here: http://msdn.microsoft.com/en-US/data/jj574232
Jan 31, 2013 09:52 AM|LINK
Got it:
return ctx.Appointments.Include("Contact").Include("Contact.ContactType").ToList();
billcrawley
Member
341 Points
286 Posts
Entity Framework - returning chained objects
Jan 31, 2013 09:38 AM|LINK
Hi all,
I have an appointment object linked to a contact object linked to a contact type object.
I can perform an eager-load on the appointment object to contact object with :
using (EnvoyModelContainer ctx = new EnvoyModelContainer()) { return ctx.Appointments.Include("Contact").ToList(); }and this will return my records.
howver, because ther is no direct relationship between appointment and contact type I cannot do this:
using (EnvoyModelContainer ctx = new EnvoyModelContainer()) { return ctx.Appointments.Include("Contact").Include("ContactTypes").ToList(); }What should I do to return my chained objects?
DarrellNorto...
All-Star
86809 Points
9646 Posts
Moderator
MVP
Re: Entity Framework - returning chained objects
Jan 31, 2013 09:46 AM|LINK
Unfortunately you can't daisy chain Includes because of how those work. You can make it work like this:
ctx.Appointments.Include("Contact.ContactTypes").ToList();You can see more on loading related entities here: http://msdn.microsoft.com/en-US/data/jj574232
Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
billcrawley
Member
341 Points
286 Posts
Re: Entity Framework - returning chained objects
Jan 31, 2013 09:52 AM|LINK
Got it:
return ctx.Appointments.Include("Contact").Include("Contact.ContactType").ToList();