New Posts New Posts RSS Feed: OnPropertyChanged never fires for Navigation properties
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

OnPropertyChanged never fires for Navigation properties

 Post Reply Post Reply
Author
Sinnema View Drop Down
Groupie
Groupie
Avatar

Joined: 23-Mar-2009
Location: Muri AG, EU, CH
Posts: 54
Post Options Post Options   Quote Sinnema Quote  Post ReplyReply Direct Link To This Post Topic: OnPropertyChanged never fires for Navigation properties
    Posted: 03-Sep-2009 at 6:36pm
Hi,
 
Today we tried to implement a OnPropertyChanged for a Navigation property. The idea is as follows. We have a Person (one) entity which has a subset called LastName (many). I've discussed this in another thread (http://www.ideablade.com/forum/forum_posts.asp?TID=1345).
 
We had an 'AfterSet' for this property which was never fired when changes were made in the RelatedEntityList LastName. So we thought, why don't we add a PropertyChanged to the LastName in the Person object, so we can track the changes made to that list. We've done extensive testing but found that the OnPropertyChanged never fired. Is it a bug?
 
Regards,
Paul Sinnema
Diartis AG
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 08-Sep-2009 at 2:40pm

Paul, a couple of questions:

  1. Were you expecting PropertyChanged to fire on the parent when an internal change was made to one of the children, or when the list of children changed (by an addition or removal). It should not fire in the former case, but should in the latter. Did you find that it wasn't firing in the latter case?

  2. I was able to get PropertyChanged to fire on an Order (parent) entity in response to an internal change made to one of the Order's OrderDetails(i.e., one of the parent's children). To do so, I implemented an AfterSet property interceptor as follows:

    [AfterSet(EntityPropertyNames.UnitPrice)]
    public void UnitPriceChanged(PropertyInterceptorArgs<Order, Decimal> args) {
      PropertyChangedEventArgs eventArgs = new PropertyChangedEventArgs("OrderDetails");
      this.Order.EntityAspect.ForcePropertyChanged(eventArgs);
    }

Is that what you are trying to do?

Note that, in instigating the raising of the PropertyChanged event on the parent, I indicated the parent's collection property (OrderDetails) as the property that changed, even though, strictly speaking, the list didn't change, only the internal details of one of its members.

Incidentally, I'm not obligated to indicate any particular property in my call to ForcePropertyChanged(). If I don't want to indicate a particular property, I can pass a null to the PropertyChangedEventArgs constructor.

Greg



Edited by GregD - 08-Sep-2009 at 2:45pm
Back to Top
Sinnema View Drop Down
Groupie
Groupie
Avatar

Joined: 23-Mar-2009
Location: Muri AG, EU, CH
Posts: 54
Post Options Post Options   Quote Sinnema Quote  Post ReplyReply Direct Link To This Post Posted: 09-Sep-2009 at 6:22am
Greg,
 
I guess you're right. We've solved this using an Intercepter in the Class itself like
 
  public override void InitEntity(InitEntityCommand initEntityCommand)
  {
   base.InitEntity(initEntityCommand);
   switch (initEntityCommand)
   {
    case InitEntityCommand.Load:
    case InitEntityCommand.Create:
     InitLastNameInterceptor();
     break;
    default:
     break;
   }
  }
  private bool m_LastNameInterceptorInitialized = false;
  /// <summary>
  /// Initialize an interceptor for Name property of LastName to set the FullName property on Person
  /// </summary>
  private void InitLastNameInterceptor()
  {
   // Prevent more than 1 initialization of the Interceptor
   if (!m_LastNameInterceptorInitialized)
   {
    PropertyInterceptorAction nameAction = new PropertyInterceptorAction<DataEntityPropertySetInterceptorArgs<DomainModel.LastName, String>>(
                 typeof(DomainModel.LastName),
                 DomainModel.LastName.EntityPropertyNames.Name,
                 PropertyInterceptorMode.AfterSet,
                 NameSetter);
    PropertyInterceptorManager.CurrentInstance.AddAction(nameAction);
    m_LastNameInterceptorInitialized = true;
   }
  }
  /// <summary>
  /// Is called when the interceptor for Name in LastName is fired.
  /// </summary>
  /// <param name="args"></param>
  private void NameSetter(DataEntityPropertySetInterceptorArgs<DomainModel.LastName, String> args)
  {
   SetFullName();
  }
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down