InMemory provider deletes wrong entry when DELETE and ADD for same PK #25905
Labels
area-in-memory
area-save-changes
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
Description
When using the InMemory provider, DELETING and ADDING entities with the same PK in the same SAVE operation will cause a concurrency violation (if concurrency is turned on). This is happening because the InMemoryStore class is deleting the wrong entity.
See fork for fix and unit test code: https://github.com/dtkujawski/efcore/tree/InMemorySharedEntry
Commit: dtkujawski@9e9c7f3
Example Code
Root cause
I believe the issue is here:
efcore/src/EFCore.InMemory/Storage/Internal/InMemoryStore.cs
Lines 176 to 184 in 86a6983
Instead of
table.Delete(entry);
I believe it should betable.Delete(entry.SharedIdentityEntry);
Stack traces
Version information
EF Core version: 5.0
Database provider: InMemory
Target framework: 5.0.9
Operating system: Windows
IDE: Visual Studio 2019 16.9.6
The text was updated successfully, but these errors were encountered: