I’m using entity framework 4.
I have 2 objects : a Process object, and a ProcessDescription object. There is a one to one association between the Process and the ProcessDescription (a Process always have a ProcessDescription)
I’m doing the following:
using (EFEntities ef = new EFEntities(ConnectionString.EFConnString))
{
var source = ef.Process;
List<BusinessLayer.Process> processList = source.ToList();
}
After the ToList statement, if I inspect the processList in the debugger, I can see that the ProcessDescription object is available for each Process, and I’m wondering why. I thought I had to write the .Include(“ProcessDescription”) to include them. Is it automagically loaded because it’s a one-to-one association?
Update: The EnableLazyLoading is indeed set to true. My question is: If that property is set to true, I thought that the related entities would be loaded, but only when needed. To check if it’s loaded, we can use the IsLoaded flag on the related entities. However, in my case, there is no IsLoaded property on my ProcessDescription object. Does it mean that when I do the ‘ToList()’ there is a inner join that is performed automatically, again because it’s a one-to-one relationship?
Turn lazy loading off and you will see null values in the debugger.
http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.contextoptions.aspx
(assuming Database First with ObjectContext)