dotnet / dotnet/EntityFramework.Docs

Is there a missing statement in EFCore documentation about Lazy Loading?

Open
#3,346 0 comments 0 reactions 0 assignees View on GitHub
area-query-related-data
Dominant language
Mermaid
Stars
1.7k
Forks
2k
Avg merge
7d 23h
Merged PRs (30d)
16

Description

I enabled Lazy Loading with proxies and the documentation [here](https://docs.microsoft.com/en-us/ef/core/querying/related-data/) says "_Lazy loading means that the related data is transparently loaded from the database **when the navigation property is accessed.**_"

I was struggling with a navigation property update trying to set the navigation property to null. It didn't work because apparently EFcore loads the Entity from the database after null assignment (probably never and it doesn't detect changes) and I had to use eager loading to made it work (I have to thank [this](https://stackoverflow.com/questions/12828739/entity-framework-set-navigation-property-to-null) stackoverflow post).

I know I can use Remove method, but it's not what I want because I created a custom entity validator to use before SaveChanges and I want that property to be null in some cases to fail the validation.

The documentation of [EF6](https://docs.microsoft.com/en-us/ef/ef6/querying/related-data#lazy-loading) about lazy loading says "_Lazy loading is the process whereby an entity or collection of entities is automatically loaded from the database **the first time that a property referring to the entity/entities is accessed.**_" and I think is clearer then EFCore one.

So my questions are:

- Do you think the doc should be clearer?
- Did I miss something in the doc?


Thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.