+3  A: 

I think the issue you are experiencing here is that by default the EF does not automatically load related entities. If you load an entity, the collection or reference to related entities will be empty unless you do one of the following things:

1) Use eager loading in order to retrieve your main entity and your related entity in a single query. To do this, modify your query by adding a call to the Include method. In your sample above, you might use the following query:

from a in context.Actions.Include("Actor") select a

This would retrieve each of the actions with the related Actor method.

2) Use explicit lazy loading to retrieve the related entity when you need it:

action1.ActorReference.Load()

In the version of the EF which will ship with .Net 4.0, you will also have the following additional option:

3) Turn on implicit lazy loading so that related entities will automatically be retrieved when you reference the navigation property.

  • Danny
Danny
I think you're right. Would be nice if EF 1.0 came with implicit lazy loading, though, since it'll be a year until we get .NET 4.0 and EF 2.
Chris Charabaruk
This does indeed solve my problem. Thanks!
Chris Charabaruk