views:

1642

answers:

2

I'm in a situation where I am being informed from an outside source that a particular entity has been altered outside my current datacontext. I'm able to find the entity and call refresh like so

MyDataContext.Refresh(RefreshMode.OverwriteCurrentValues, myEntity);

and the properties which have been altered on the entity are updated correctly. However neither of the INotifyPropertyChanging INotifyPropertyChanged appear to be raised when the refresh occurs and this leaves my UI displaying incorrect information.

I'm aware that Refresh() fails to use the correct property getters and setters on the entity to raise the change notification events, but perhaps there is another way to accomplish the same thing?

Am I doing something wrong? Is there a better method than Refresh? If Refresh is the only option, does anyone have a work around?

A: 

If you know to call Refresh(), why not just go ahead and refresh the UI at that point anyway?

PropertyChanging and PropertyChanged are invoked by invoking the setter on a LINQtoSQL DBML-generated entity class. Calling Refresh() does not do that:

[Column(Storage="_DisplayName", DbType="VarChar(50) NOT NULL", CanBeNull=false)]
public string DisplayName
{
    get
    {
     return this._DisplayName;
    }
    set
    {
     if ((this._DisplayName != value))
     {
      this.OnDisplayNameChanging(value);
      this.SendPropertyChanging();
      this._DisplayName = value;
      this.SendPropertyChanged("DisplayName");
      this.OnDisplayNameChanged();
     }
    }
}
Rex M
Rex,The Refresh() is done at a Controller/"Almost Business Layer" level, its nowhere near the UI so a manual refresh is out of the question.If Refresh() changes the Enitity data it should be raising changed events – the fact that it doesn’t do its seems like a gross oversight to me.
Scott
@Scott maybe it is an oversight, but that is code we can't change, whereas yours is. Why not add an event to your DataContext class that you invoke when you call Refresh() and attach to that from the UI? That is close to the SoC you get from an event in the entity.
Rex M
A: 
Casey Gay