-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[EFC5] Sharing the same .NET type among multiple owned types loses EntityState.Deleted tracking in ChangeTracker #23418
Comments
@AndriySvyryd Why does the Deleted entry show up for non-weak types, but not for weak types? The end result is the same in both cases for owned entities; an update to the database rather than adds and deletes. |
We discussed this in triage and it does seem like a bug, or at least something that could be improved. However, we are currently moving away from weak entity types for shared owned types--see #22378. We will revisit this issue for 6.0 after completing that work. |
Is there a recommended approach for auditing these weak types in the meantime? This auditing is a strict requirement for the project I am working on. Would it be best to remove the "owning" relationship and turn the "owned" entities into full-fledged entities, having their own table? Or is there a better alternative? Thank you. |
@HaisojYellams Yes, you'd need to avoid calling Owns* targeting a particular entity type more than once to avoid it becoming weak. |
Remove null-checking code for IProperty.GetValueComparer() Make DebugString terser for Indexes and keys on STETs Remove extra UsingEntity in ManyToManyQueryFixtureBase Fixes #23418
Remove null-checking code for IProperty.GetValueComparer() Make DebugString terser for Indexes and keys on STETs Remove extra UsingEntity in ManyToManyQueryFixtureBase Fixes #23418
Remove null-checking code for IProperty.GetValueComparer() Make DebugString terser for Indexes and keys on STETs Remove extra UsingEntity in ManyToManyQueryFixtureBase Fixes #23418
If the same .NET type (class) is used for two Owned Types on an entity, the
DbContext
'sChangeTracker
no longer detects when those types areDeleted
. However, if the Owned Type is used exactly once, it will track it.In the example below, you can see that the
Names
property is shown as bothAdded
andDeleted
on the second save (which, I believe) is the expected outcome. However, both theCurrentLocation
andHomeLocation
properties only showAdded
states - noDeleted
.(This scenario arose for me while attempting to set up an audit - I need to know the values in the deleted type as well as the newly added values.)
Click to see Entities/DbContext
Click to see driver Program
Click to see the output of running the program
Click to see .csproj file
EF Core version: 5.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: netcoreapp3.1
Operating system: Fedora 31
IDE: Rider 2020.2.4
The text was updated successfully, but these errors were encountered: