1

I've created an object in entity framework and want to include some related classes after the fact. How can I do this or what keywords should I be searching for?

Order myOrder = 

context.Orders
        .Include("Category")
        .Include("Customer");

// Some logic here


myOrder = myOrder.Include("Supplier");
John Zumbrum
  • 2,786
  • 8
  • 36
  • 60
  • 1
    "*Explicit Loading*" is the keyword you can search for. If you tell us the EF version you are using and if you use `ObjectContext` or `DbContext` someone might answer with an example. – Slauma Jul 12 '12 at 22:05
  • Ah, thanks! Will have to do some research on ObjectContext vs. DbContext as I'm working inside of someone else's system, but I do know I'm using POCO objects. – John Zumbrum Jul 12 '12 at 22:08
  • 1
    If you use POCOs with `ObjectContext` then it might be a problem. As far as I know in that constellation explicit loading is not supported. We have to look for another solution then (like simply querying the child entity/collection and assign it to the navigation property in `myOrder`, or something...). – Slauma Jul 12 '12 at 22:38
  • Explicit loading works with ObjectContext as well but you must turn lazy loading off. Btw. why are you not using lazy loading? – Ladislav Mrnka Jul 13 '12 at 08:57
  • Well I finally got it out of who set this up originally that the late loading or w/e it's called has been turned off. The idea being not wanting to carry the database connection around everywhere? Seemed to me like it would make things way more useful. – John Zumbrum Jul 13 '12 at 13:30
  • 1
    I guess @Ladislav meant something like this when using explicit loading with POCOs and `ObjectContext`: http://stackoverflow.com/questions/3398445/using-createsourcequery-in-ctp4-code-first So, my second comment above is not quite correct. – Slauma Jul 16 '12 at 13:08

0 Answers0