-
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
DbUpdateException should not leave the context in a bad state #29060
Milestone
Comments
Note for triage: The context should be considered in an invalid state after an |
Note from triage: DbUpdateException should not leave the context in a bad state. |
ajcvickers
added
consider-for-current-release
and removed
consider-for-next-release
labels
Oct 20, 2022
ajcvickers
changed the title
EF wrongly adds items
DbUpdateException should not leave the context in a bad state
Dec 8, 2022
AndriySvyryd
added
consider-for-next-release
and removed
consider-for-current-release
labels
Sep 29, 2023
AndriySvyryd
added
consider-for-current-release
and removed
consider-for-next-release
labels
Oct 18, 2023
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
EF is wrongly adding (persisting) an entity when a duplicate key is found.
Consider the following Entity, when Name is set as Alternate Key:
Then consider the following scenario:
One would not expect Entity1 to be saved after an error occured when adding it to the Dbset.
Yet, it looks like it is left in DbSet.Local and, with an Added State and is Added to the Db once Entity1 is removed.
Exception on step 3 is:
The following code simulates that process:
It seems the DbSet.Local is wrongly updated with the entity even though an exception was thrown during the call to .Add
A full console app sample project to reproduce this issue is attached.
EF Core version: 6.0.8
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
EFDuplicateKey.zip
The text was updated successfully, but these errors were encountered: