Data Access has been discontinued. Please refer to this page for more information.

How to: Implement the INotifyPropertyChanged/ing Interfaces

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

For the cases that require you to track the value changes of the domain properties, Telerik Data Access can implement the INotifyPropertyChanged and INotifyPropertyChanging interfaces directly in the definition of the domain classes.

You can choose whether to implement these interfaces during either the creation of the domain model or on a later stage when you modify it.

This topic will demonstrate to you how to control the implementation of INotifyPropertyChanged and INotifyPropertyChanging. The necessary settings can be found on the Code Generation Settings page in either the Advanced Options dialogue of the Create Model wizard or the Code Generation Settings tab in the Model Settings dialogue.

The process is as follows:

  1. Navigate to the Advanced Options dialogue of the Create Model wizard or open the Code Generation Settings tab in Model Settings.
  2. In the Code Generation Options section check the Implement INotifyPropertyChanged (INotifyPropertyChanging) Interface check-box

The Implement INotifyPropertyChanged/ing options are available only in Visual Studio 2010 and Visual Studio 2012.

  1. Click Finish if you are using the wizard or OK for Model Settings
  2. Save the domain model if you are using the Model Settings dialogue

In both cases the domain classes will implement the selected interfaces:

public partial class Category : INotifyPropertyChanging, INotifyPropertyChanged
{
    private int _categoryID;
    public virtual int CategoryID
    {
        get {   return this._categoryID;    }
        set
        {
            if(this._categoryID != value)
            {
                this.OnPropertyChanging("CategoryID");
                this._categoryID = value;
                this.OnPropertyChanged("CategoryID");
            }
        }
    }

    private string _categoryName;
    public virtual string CategoryName
    {
        get {   return this._categoryName;  }
        set
        {
            if(this._categoryName != value)
            {
                this.OnPropertyChanging("CategoryName");
                this._categoryName = value;
                this.OnPropertyChanged("CategoryName");
            }
        }
    }

    private IList<Car> _cars = new List<Car>();
    public virtual IList<Car> Cars
    {
        get {   return this._cars;  }
    }

    public event PropertyChangingEventHandler PropertyChanging;
    protected virtual void OnPropertyChanging(string propertyName)
    {
        if(this.PropertyChanging != null)
        {
            this.PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged(string propertyName)
    {
        if(this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
Partial Public Class Category
    Implements INotifyPropertyChanging, INotifyPropertyChanged
    Private _categoryID As Integer
    Public Overridable Property CategoryID() As Integer
        Get
            Return Me._categoryID
        End Get
        Set(ByVal value As Integer)
            If Me._categoryID <> value Then
                Me.OnPropertyChanging("CategoryID")
                Me._categoryID = value
                Me.OnPropertyChanged("CategoryID")
            End If
        End Set
    End Property

    Private _categoryName As String
    Public Overridable Property CategoryName() As String
        Get
            Return Me._categoryName
        End Get
        Set(ByVal value As String)
            If Me._categoryName <> value Then
                Me.OnPropertyChanging("CategoryName")
                Me._categoryName = value
                Me.OnPropertyChanged("CategoryName")
            End If
        End Set
    End Property

    Private _cars As IList(Of Car) = New List(Of Car)()
    Public Overridable ReadOnly Property Cars() As IList(Of Car)
        Get
            Return Me._cars
        End Get
    End Property

    Public Event PropertyChanging As PropertyChangingEventHandler
    Protected Overridable Sub OnPropertyChanging(ByVal propertyName As String)
        RaiseEvent PropertyChanging(Me, New PropertyChangingEventArgs(propertyName))
    End Sub

    Public Event PropertyChanged As PropertyChangedEventHandler
    Protected Overridable Sub OnPropertyChanged(ByVal propertyName As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
    End Sub
End Class

If the domain classes were created with implementation of these interfaces and at some point you uncheck Implement INotifyPropertyChanged Interface or Implement INotifyPropertyChanging Interface, it will be removed once you save the model. You can restored it by applying the described process.