+3  A: 

Using ADO.NET Entities, you need to specify what entities you want to load automatically with Include, as in

Dim entity = (From e in db.Entities.Include("SubEntity"))
Paulo Santos
Perfect, that solved it, thanks!I guess what I still don't understand though is, why do two of the references load automatically, and two of them don't?
gerrod
@Paulo: That's not entirely true (at least as of EF 4, I never worked with EF 1). You CAN specify which references you want to load automatically (and immediately), but you CAN also rely on lazy loading to load as needed. However, lazy loading seems broken even in EF 4 so this is probably still the correct answer from a practical perspective. See http://msdn.microsoft.com/en-us/library/bb896272.aspx
Eric J.
A: 

This was done in EF v1 as a design decision, and many developers actually prefer having explicit control over if and when referenced properties will be loaded.

For EF v4 coming out with .NET 4.0 before the end of 2009, you'll have the option to turn on automatic deferred loading, if you so wish. See this blog post on the ADO.NET team blog for more information on deferred loading in EF v4.

Marc

marc_s
That's true, Marc, but the problem with deferred loading is that there's a lot of queries on the database, and should be used wisely.Depending on what one needs, it's simple to pre-load the entities.
Paulo Santos
+2  A: 

As others have said you need to .Include() in v1 to avoid needing to call .Load()

In 4.0 you will be able to set DeferredLoadingEnabled on your ObjectContext (I think we are changing this name to the more appropriate LazyLoadingEnabled in time for Beta2).

As for why you get 2 relationships already loaded anyway. That is probably a side-effect of something called Relationship Fix-up.

When two related entities are in the same Context, they automatically get their relationship's fixed to point to each other. So if (as I suspect) 2 of the 4 entities are already in your context, when you do the query, you will end up in a situation where 2 of your relationships are loaded, even though you didn't call .Include() or .Load().

Hope this helps

Cheers Alex

Alex James
Ah! Thanks for that, makes perfect sense.
gerrod