dotnet / dotnet/efcore

IsModified is false when setting owned entity to null

Open
#36,368 0 comments 1 reaction 1 assignee Claimed by @AndriySvyryd View on GitHub
area-change-tracking
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

Hi

I have a `SaveChangesInterceptor` where I check for changes in entries' properties and navigations and run business logic accordingly (for example, notifying other system about changes in the data). I've ran into an issue with references to owned entity types. I'm checking the `ReferenceEntry.IsModified` field to see if the references were changed and this works well in case of adding a new reference (i.e. from `null` to not `null`) and changing references (i.e. from not `null` to not `null`). However, when removing a reference (i.e. setting a not `null` reference to `null`) I see that `IsModified == false`.

This is an unintuitive behavior since the reference was indeed modified. I don't expect to have a reference to the deleted owned entity, just an indication that the current `null` set for the reference is a modification made in the current transaction.

I see that there was an issue report regarding this [back in 2022](https://github.com/dotnet/efcore/issues/27848) which was closed after an alternative was suggested for the OP's specific use case but the bug was never fixed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.