Print Page | Close Window

navigation to a parent

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1832
Printed Date: 21-Apr-2026 at 10:39am


Topic: navigation to a parent
Posted By: downeytim
Subject: navigation to a parent
Date Posted: 20-May-2010 at 7:35am
I have a situation where a specific entity has had a property change.  I want to propagate that property change to each of the parent of this child.  This child has children also. 
 
I tried getting the NavigationProperties of the entity and tried to figure out which were parent relations, but alas I can't seem to quite get it.  Can you point me at some code to accomplish this?
 
Thanks.



Replies:
Posted By: ting
Date Posted: 21-May-2010 at 4:56pm
Sorry I'm confused by the phrase "each of the parent of this child". Can you describe the object graph in greater detail?
  
I think you are asking how to propagate a property change recursively down a single dependent navigation path.
 
For example, a manager employee has "direct report" employees. Some of these might also be managers with their own "direct reports".
 
You are proposing that a change to the CEO, say, should result in a property change raised on the CEO's direct reports, and then on their reports and so forth.
 
If so, the next question is "what property name should be raised?" What do you want to have happen to each child and what should be passed down to the nex child?  I'm not sure what repeatedly raising the "DirectReports" property, for example, is supposed to accomplish.
 
I'm at a loss until I understand the scenario more clearly.
 


Posted By: downeytim
Date Posted: 24-May-2010 at 3:35am
I am sorry I was not clear.  But you raise some good questions as to why our legacy code does this.  Be that as it may what I need to do is, using your example, when a property changes on an employee record (any property) I want to raise a property changed event on the manager.  The property changing on the manager is the employee that changed in the first place.
 
Does this make more sense?  I don't really know what the scenario is that supports this as we are merely migrating legacy code to a new version of Ideablade and the DevExpress controls.


Posted By: WardBell
Date Posted: 24-May-2010 at 8:32pm

Hey ... stuff happens.

But it wasn't an idle question because I don't know what string to pass to the PropertyChangedEventArgs for the manager.
 
Anyway, the following code, which would go inside the Employee custom partial class, works for the "Employee.Manager" scenario we've discussed.
 
Observe that I dreamed up a string to send as the "PropertyName" when I raise PropertyChanged on the manager (which I do via the EntityAspect.ForcePropertyChanged method).
 
I feel strongly that this is not a wise idea. You be the judge.
 
---
 
     protected  override  void  OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs  e) {
       if  (HeardDirectReportChanged(e)) return ;
       base.OnPropertyChanged(e);
       RaiseManagerPropertyChanged();
     }
 
     // Note: Don't recommend this approach at all.   
     // PropertyChanged is not raised for every change to an employee. 
     // PropertyChanged not raised when entity changes are rolled back 
     // e.g., after IEditableObject.CancelEdit or RejectChanges 
     // Manager won't hear about any of these events via this mechanism 
 
     private  bool  HeardDirectReportChanged(PropertyChangedEventArgs  e) {
       var  propertyName = e.PropertyName;
       if  (!propertyName.StartsWith("DirectReport '" )) return  false ;
       // Do something 
       var  x = this.FullName + " heard from " + propertyName;
       return  true ; // assume don't actually want to continue with PropertyChanged 
     }
 
     private  void  RaiseManagerPropertyChanged() {
       var  mgr = this.Manager;
       var  mgrEa = Manager.EntityAspect;
       var  selfEa = this.EntityAspect;
 
       // Reasons not to continue 
       if  (this  == mgr ||                      // if manage oneself 
            !selfEa.IsChanged ||                 // self unchanged 
            selfEa.EntityState.IsDetached() ||   // self is detached 
            mgrEa.IsNullEntity ||                // have no manager 
            mgrEa.EntityState.IsDetached()       // manager is detached 
           ) return ;
 
 
       mgr.EntityAspect.ForcePropertyChanged(
         new  PropertyChangedEventArgs (
           string .Format("DirectReport '{0}: {1}'" , EmployeeID, FullName)));
     }
 



Print Page | Close Window