The dirty state of an entity is monitored by the data context. This is usually accomplished with change notifications, provided through the INotifyPropertyChanging.PropertyChanging
and INotifyPropertyChanged.PropertyChanged
events, raised in the property setters of the entity.
Combining the PropertyChanged
and PropertyChanging
events raising into every property setter can add up to a lot of plumbing code. Fortunately the Assign
method, in the custom ViewModelBase
class, used throughout this book, raises the events required for change tracking.
For more information on the property change notification, in relation to the ViewModelBase
class, see Chapter 2.
For entities that do not implement INotifyPropertyChanging
, LINQ to SQL maintains a copy of their values. When DataContext.SubmitChanges
is called, the current and original values are compared to determine whether the object has changed.
Tip
To decrease the amount of memory used by your app, ensure that entity classes implement INotifyPropertyChanged
and INotifyPropertyChanging
.
18.116.35.5