You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My assumption here is that SaveChanges returns the number of entries that have been updated.
0 if no entity was found and updated
1 (or higher) when found and updated.
This works fine if a corresponding entity exists (>0)
If an entity does not exist (=0) and therefore nothing could be found, then a DBConcurrencyException is thrown.
DbUpdateConcurrencyException: Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded.
Note for team: I haven's seen requests for "update or ignore" behavior before. (As opposed to the common request for "update or insert".) We should discuss.
Also consider #16949 when doing this as well as disabling other constraints (NOCHECK CONSTRAINT), there could be an overarching API for suppressing checks on SaveChanges
I would like to update a property of an entity without having to perform a round-trip.
The expected behavior of the method is:
For this I use the following code snippet:
My assumption here is that SaveChanges returns the number of entries that have been updated.
This works fine if a corresponding entity exists (>0)
If an entity does not exist (=0) and therefore nothing could be found, then a DBConcurrencyException is thrown.
DbUpdateConcurrencyException: Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded.
My temporary solution is that I have to do the roundtrip (select first, then update, if exists)
Is this behavior by design or unintentional?
I could not find any documented behavior.
Further technical details
EF Core version: 3.1.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer 3.1.0
Target framework: (e.g. .NET Core 3.1)
Operating system: Windows 10.0.18363.535
IDE: VS2019 Version 16.5.0 Preview 1.0
The text was updated successfully, but these errors were encountered: