Search for existing suggestions

Throw exception when you attempt to access a navigation property that is not loaded

Of course this should be an optional feature that can be enabled from the DbContext configuration. It only makes sense when Lazy Loading is disabled.

This will be particularly useful for writing domain models that are independent of the data access technology and thus cannot use the EF functions to check whether a property is loaded.

Currently, if the logic inside the domain model tries to access a navigation property that is not loaded, this will either fetch the data from the database if lazy loading is enabled (a lot of developers do not like lazy loading) or, if lazy loading is disabled, the logic will incorrectly think that the navigation property is null or an empty collection.

8 votes
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)

We’ll send you updates on this idea

Bassem Mohsen shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

1 comment

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...
  • Anonymous commented  ·   ·  Flag as inappropriate

    This behaviour is considered as a BUG! You end up with no warning and you wrongly assume there's no data.

    We already wasted hours of work on debugging a production system because of this behaviour. And it was just our LUCK that we haven't used the same code on write operations, cause that could have lead to stale data!

Feedback and Knowledge Base