For all of my POCOs, the navigation and collection properties are all null.
Let me provide some background. I have a complex code first project using EF 4.3.1. Proxy generation was disabled. Collection and navigation properties were managed manually.
I'm now enabling proxy creation and lazy loading. When debugging, I can see that my entity (which is cast to my known POCO type) is now actually an auto generated proxy class. So far so good.
Now, when I look at my navigation properties, they are null. Similarly, my collection properties are null.
Using reflection, I can see that the proxy class HAS overridden my navigation and collection properties.
All navigation and collection properties are virtual. e.g:
public virtual NavigationType NavigationName { get; set; }
public virtual ICollection<CollectionType> CollectionName { get; set; }
Also, all tables are initialised as such:
modelBuilder.Entity<TEntity>()
.Map(m =>
{
m.MapInheritedProperties();
m.ToTable("TableName");
});
I can also confirm that the database is generated as expected. Foreign keys are all present and are associated with the expected fields.
Why are they null? How can I diagnose this further?