views:

170

answers:

1

Hi all,

I am new to Entity Framework and please pardon my ignorance. We have a simple application written using SQL Server and ADO.Net. Now we have got a new requirement that, whenever a particular rows get updated by our application, some business logic has to happen. I have been looking into Triggers in SQL server and it looks like we can do it using triggers. I am also looking at Entity Framework's OnPropertyChange capability. Is it possible to do it with "OnPropertyChange"?

I mean, Can I create a model and implement "OnPropertyChange" method? And when our application modifies the rows using ADO.Net, then will it fire "OnPropertyChange" event so that my custome code in "OnPropertyChange" excutes?

Thank you in advance for your inputs,

Suresh

+2  A: 

Triggers occur whenever an action happens on the database table itself. If you perform an update and have an update trigger, this will happen regardless of whether you use Entity Framework or write an update statement directly against that table. Here is a reference on SQL Server Triggers.

EDIT If you want custom business logic to occur that either pertains or doesn't pertain to the database you can do the following:

    private string _myProperty;    
    public string MyProperty
    {
        get 
        {
            return _myProperty;
        }
        set
        {
              if (_myProperty != value)
              {
                 _myProperty = _value;
                 OnPropertyChanged("MyProperty");
                 DoSomethingWithMyProperty(_myProperty);
               }
          }
     }

In the DoSomethingWithMyProperty method you can do whatever you would like, whether it be update your UI or database.

Blake Blackwell
Thank you for your reply. My question is, if an appliaction modifies a field (cell) in database, then OnPropertyChange in someother application be called?
jaklucky
The OnPropertyChanged method provided in Silverlight/WCF pertains to the class property member. Calling OnPropertyChanged within .NET will let .NET know about the change, not the database. However,when you save changes back to the database the triggers that have been placed on the updated table will execute. Does that make sense?
Blake Blackwell
Thank you. I guess it answered my question. So, trigger is the way to go in my situation then.
jaklucky