EntityFramework.Docs icon indicating copy to clipboard operation
EntityFramework.Docs copied to clipboard

Confusing description of Tracking queries

Open space-alien opened this issue 2 years ago • 2 comments

"Query results don't contain any entity, which is added to the context but not yet saved to the database."

This is confusingly written. Does this mean to convey that a query will never return any entity that exists in the context in the Added state?


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

space-alien avatar Apr 09 '22 19:04 space-alien

Yes - queries return entities from the database, so any entity instance not yet saved won't be returned.

roji avatar Apr 10 '22 11:04 roji

Thanks Shay. Might I suggest rephrasing the documentation along these lines:

When the results are returned in a tracking query, EF Core will check if the entity is already in the context. If EF Core finds an existing entity, then the same instance is returned. EF Core won't overwrite current and original values of the entity's properties in the entry with the database values. If the entity isn't found in the context, then EF Core will create a new entity instance and attach it to the context. Queries only return entities that already exist the database. Any unsaved entities in the context will not be included in query results.

space-alien avatar Apr 11 '22 12:04 space-alien