views:

763

answers:

2

Hi,

I have three tables: Scenarios, Components and Blocks. Blocks has a foreign key to ComponentId and Components has a foreign key to Scenarios.

Blocks also has a foreign key (TreeStructureId) to another table TreeStructures.

Now, why does this work:

ObjectQuery<Blocks> blocks = edumatic3Entities.Blocks.Include("TreeStructures").Include("Components.Scenarios");

It loads the TreeStructures, Components and Scenarios.

This however doesn't work:

ObjectQuery<Blocks> blocks = edumatic3Entities.Blocks.Include("Components.Scenarios").Include("TreeStructures");

This loads the Components and Scenarios but doesn't load the TreeStructures...

Seems very strange to me... Why is this?

thx, Lieven Cardoen

A: 

Did you properly set the relations between the entities in your logical model? Is it set up in a way that allows navigation from Scenarios s to TreeStructures? Having a foreign key is not enough afaik.

driAn
Yes, it is set, otherwise I guess the first example of code wouldn't work either. That's the strange thing you see. It's like the order of the Include matters...
Lieven Cardoen
A: 

Seems like I fixed the problem not knowing why. Probably did something stupid.

thx.

Lieven Cardoen
However... how did you fix it?
lmsasu
If I knew, I would have written it. Anyway, using the Entity Framework was a one time thing.
Lieven Cardoen