EF Loading sub objects?

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
 
C

Chris-

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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top