How to load table data with foreign key binding also in entity framework

I developed an entity app (.edmx) in 4.0 where I got all the data of my query table and its foreign keys referenced by the data of the tables as well. but when I change my project to 3.5, I cannot get the data of the tables data bound to the foreign key. Please help me...

+2


a source to share


2 answers


In EF4, lazy loading is enabled and enabled by default.

No such luck in previous versions: you may need to add .Include () to automatically fetch other data (load load) or call Load () on links to load it (manually).

If the lookup table said "Details", you would do ...



var featuredOffers = context.Hosters_FeaturedOffer.Include("Details").ToList();

      

See http://msdn.microsoft.com/en-us/library/bb896272.aspx

By the way: search for "strongly typed inclusion" - there are some extension methods people have written to remove the magic string and replace it with a lambda check time, which is compile time checked.

+4


a source


For future answers, if you are using a newer version of EF;



 var o = db.Order.Include(i => i.User).Include(i => i.OrderItem).FirstOrDefault(x=>x.OrderId == orderId);

      

+1


a source







All Articles