Telerik blogs
When you are partially giving away the control on your Data Access layer to an ORM tool, there are some things you want to keep an eye on. Based on your feedback, tracking the value changes is one of them. In order to do that, you had to modify the code generation templates we are delivering, which is not that straight forward as a task, especially if you haven't worked with T4 templates before.

We wanted to provide you a way to implement INotifyPropertyChanging or INotifyPropertyChanged in the most simple and easy way possible. So they landed as checkboxes on the modified Model Settings dialog, going live in Q2 2013 of Telerik OpenAccess ORM:



Just like that, all the generated persistent properties will automatically use those interfaces in their setters:

private DateTime _date;
[Required()]
[DataType(DataType.DateTime)]
public virtual DateTime Date
{
    get
    {
        return this._date;
    }
    set
    {
        if(this._date != value)
        {
            this.OnPropertyChanging("Date");
            this._date = value;
            this.OnPropertyChanged("Date");
        }
    }
}

Of course, the class will implement the interfaces:

public partial class Message : INotifyPropertyChanging, INotifyPropertyChanged
{
...
#region INotifyPropertyChanging members
         
public event PropertyChangingEventHandler PropertyChanging;
         
protected virtual void OnPropertyChanging(string propertyName)
{
    if(this.PropertyChanging != null)
    {
        this.PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
    }
}
         
#endregion
         
#region INotifyPropertyChanged members
         
public event PropertyChangedEventHandler PropertyChanged;
         
protected virtual void OnPropertyChanged(string propertyName)
{
    if(this.PropertyChanged != null)
    {
        this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}
         
#endregion
 
...

So far we have presented you with Data Annotation attributes and the interfaces INotifyPropertyChanged and INotifyPropertyChanging. Stay tuned and you will see what else will be auto-generated with OpenAccess ORM in Q2 2013!

Telerik DevCraft Q2 2013 Webinar Week


About the Author

Ivailo Ivanov

 is Team Lead in Telerik Data Access

Comments

Comments are disabled in preview mode.