EF Loading sub objects?

  • Thread starter Thread starter Michael Bray
  • Start date Start date
M

Michael Bray

I am playing with EF, and I have an association set up between two objects,
but when I load the Primary object, the related objects don't automatically
load. Is there something I'm missing? is this supposed to be automatic?
How do I tell EF to go ahead and load those object references that I'm
trying to get to?

So for example, I have "Customer" and "Orders". The Orders table has a
relation to customer thru "fkCustomer"... The Orders object has a
"Customer" object in the conceptual model, and Customer has "Orders" in the
conceptual model. When I load Customer, Orders is empty, even though there
is data in the DB for it.

What am I missing?

-mdb
 
I am playing with EF, and I have an association set up between two objects,
but when I load the Primary object, the related objects don't automatically
load.   Is there something I'm missing?  is this supposed to be automatic?  
How do I tell EF to go ahead and load those object references that I'm
trying to get to?

So for example, I have "Customer" and "Orders".  The Orders table has a
relation to customer thru "fkCustomer"...  The Orders object has a
"Customer" object in the conceptual model, and Customer has "Orders" in the
conceptual model.  When I load Customer, Orders is empty, even though there
is data in the DB for it.

What am I missing?

-mdb

Try using the Include() method.

var x = context.OrdersSet.Include("Orders").ToList();
 
Back
Top