Skip to content
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

Provide event that can be used to get notifications when all property changes have been detected #26506

Closed
Tracked by #22954
samuelpsfung opened this issue Nov 2, 2021 · 3 comments · Fixed by #28356
Labels
area-change-tracking area-interception closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Milestone

Comments

@samuelpsfung
Copy link

Please see attached program. I use a shadow property for one-to-many relationship, and wish to capture changes in ChangeTracker.StateChanged event. When the parent relationship changed, the current value in the event is still the same as the original one.

image
EFEvents.zip


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@samuelpsfung
Copy link
Author

In ChangeTracker.StateChanged, why is e.Entry.Reference("Parent").IsModified false although the parent reference has been replaced?

Also, how to rewrite the answer after this breaking change? INavigationBase.ForeignKey is missing

@ajcvickers ajcvickers transferred this issue from dotnet/EntityFramework.Docs Nov 2, 2021
@ajcvickers
Copy link
Contributor

Note for triage: The state changed event happens as soon as an entity is detected as modified, which in this case happens when the Name property is detected as changed. At this time the FK property has not yet been detected as changed. We should consider delaying this event until all properties of the entity have gone through change detection.

@samuelpsfung To answer your second question, cast the INavigationBase to an INavigation.

@ajcvickers ajcvickers self-assigned this Nov 2, 2021
@ajcvickers ajcvickers added this to the Backlog milestone Nov 2, 2021
@ajcvickers ajcvickers changed the title How to capture new value in shadow property of one-to-many relationship? Delay entity state changed event until all property changes have been detected Nov 2, 2021
@ajcvickers ajcvickers modified the milestones: Backlog, 7.0.0 Jun 22, 2022
@ajcvickers ajcvickers changed the title Delay entity state changed event until all property changes have been detected Provide event that can be used to get notifications when all property changes have been detected Jul 1, 2022
ajcvickers added a commit that referenced this issue Jul 1, 2022
… when all changes for an entity have been detected

Fixes #26506

Also disable auto-DetectChanges when in the event to prevent infinite loop of recursive calls.
@ajcvickers
Copy link
Contributor

On further investigation, delaying the event is not appropriate since the state must change when the first property change is detected. However, the new DetectChanges events can be used to achieve the desired notification here--see #28356

@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 1, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0, 7.0.0-preview7 Jul 7, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0-preview7, 7.0.0 Nov 5, 2022
@ajcvickers ajcvickers removed their assignment Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-change-tracking area-interception closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Projects
None yet
3 participants