Setting foreign key to null by PropertyEntry.CurrentValue deletes entity #25360
Labels
area-change-tracking
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
Given is an entity with a self-referencing relationship that is configured with
DeleteBehavior.Cascade
.When setting the foreign key to null using the
PropertyEntry.CurrentValue
, theEntityEntry.State
changes toDeleted
and thereby the call toSaveChanges
deletes the entity.I created a simple app here: (https://github.com/majbo/EFCascadeDeleteError)
Execute the unit tests. The first one succeeds, it sets the foreign key directly on the entity. The second one fails, it sets the foreign key using
PropertyEntry.CurrentValue
.Include provider and version information
EF Core version: 5.0.8
Database provider: Microsoft.EntityFrameworkCore.Sqlite
Target framework: .NET 5.0
Operating system: Windows 10
IDE: Rider 2021.1.5
The text was updated successfully, but these errors were encountered: