-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Detecting changes to shadow properties #22991
Comments
Can you elaborate on how would you use these events? EF doesn't track property changes on Added and Deleted entities. To find the modified shadow properties you can do this: context.ChangeTracker.DetectChanges();
foreach (var entry in context.ChangeTracker.Entries())
{
if (entry.State != EntityState.Modified)
{
continue;
}
foreach (var propertyEntry in entry.Properties)
{
if (!propertyEntry.IsModified
|| !propertyEntry.Metadata.IsShadowProperty())
{
continue;
}
// TODO: react to property change
}
}
// This avoids the extra DetectChanges in SaveChanges
context.ChangeTracker.AutoDetectChangesEnabled = false;
context.SaveChanges(); This could be done in 'DetectChangesCompleted' when #16256 is implemented |
@AndriySvyryd
That's why I'm using |
I managed to do exactly what I want using internals and reflection. Thanks for writing highly readable code. Feel free to close the issue. |
Glad it worked out. In 5.0 consider using indexer properties instead of shadow properties. |
I'm working on a project where it's important to instantly detect any change made to any tracked entity. With change-tracking proxies, INotifyPropertyChanged.PropertyChanged and EF events, it's easy to instantly detect state and property changes. The only problem for me is shadow properties. I couldn't find a way to detect when a change is made to a shadow property of an entity that's Added/Modified/Deleted. I thought about value comparators/converters but they are part of the model and creating a unique model per context wouldn't be practical.
Is there any option other than forking the codebase?
The text was updated successfully, but these errors were encountered: