How can I diagnose this further?
You could check for example if the entities you are inspecting are attached to the context by looking into the change tracker's context.ChangeTracker.Entries()
collection.
It's well possible that you have a dynamic proxy with all navigation properties being null
, for example:
Entity entity = context.Entities.Create();
entity
will be a proxy, but NavigationName
and CollectionName
will be null
and they will stay null
even when you access these properties (leading to NullReferenceException
s). This will only change when you attach the entity:
context.Entities.Attach(entity);
If you access the properties now lazy loading should run. NavigationName
can stay null
if there is no related entity in the database, but the collection CollectionName
should never be null
after attaching and accessing it. If there are no related entities in the DB the result should be an empty collection, but not null
.