Skip to main content
A newer version of this page is available. .
All docs
V21.2
.NET Framework 4.5.2+

Change Tracking in EF Core DbContext and Performance Considerations

Projects created by the XAF Solution Wizard use the ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues change tracking strategy (the default setting). This strategy requires entity classes to implement the INotifyPropertyChanged and INotifyPropertyChanging interfaces.

XAF’s built-in classes do not implement the INotifyPropertyChanged and INotifyPropertyChanging interfaces. Instead, the change-tracking proxies extension is used so that the ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues strategy works correctly. This extension requires that all persistent properties in you persistent classes are declared as virtual:

public class Department : BaseObject {
    public virtual string Name { get; set; }
    // ...
}

How to Use Non-Virtual Properties

If you need to use classes with non-virtual persistent properties, the change tracking strategy requires you to manually implement the INotifyPropertyChanged and INotifyPropertyChanging interfaces for all classes that you use in your DBContext, including XAF internal classes.

As an alternative, you can use the ChangeTrackingStrategy.Snapshot strategy so your entity classes do not need to implement INotifyPropertyChanged and INotifyPropertyChanging. However, this can lead to performance issues and cause the application’s UI to incorrectly refresh the displayed data.

See Also