none
Extensibility Method Definitions, Catching association changing event RRS feed

  • Question

  • Hi, I have a quick question, in the Extensibility Method Definitions you can catch the properties changing event and implement some business logic. This seems to work fine for simple properties but when the property is an association its not catching the change.
    For ex if I have two tables, PurchaseOrders and PurchaseOrderStatus and the PurchaseOrder table has a POStatusId. When I change the status of a PO I assign it to the actual status object.
    so something like this, PO.PurchaseOrderStatus = PurchaseOrderStatus.SingleOrDefault(p=>p.id = someStatusId), I do not assign the ids directly (so I don't to PO.POStatusId = someInteger)
    This does not seem to trigger the OnPOStatusIdChanging() or ONPOStatusIdChanged() events at all.

    Thanks

    Chris
    Monday, February 8, 2010 11:45 PM

Answers

  • Hello Chris,

     

    How are you?   I am very glad to see you here again!

     

    We don’t have the **Changing or **Changed extensibility methods for navigation properties.   Once the navigation properties are modified, we use the entity’s PropertyChanged or PropertyChanging events to track.  

    ===============================================================================

    var child = db.ChildTables.First();

    child.PropertyChanged += new PropertyChangedEventHandler(child_PropertyChanged);

    child.ParentTable = db.ParentTables.First();

     

            void child_PropertyChanged(object sender, PropertyChangedEventArgs e)

            {

                MessageBox.Show(e.PropertyName);

            }

    ===============================================================================

    We will get result that it is the “ParentTable” navigation property is changed in the child_PropertyChanged event handler.  

     

     

    For the foreign key properties, they won’t be updated immediately after the navigation properties are modified.  In the above sample codes, after the codes of line: “child.ParentTable = db.ParentTables.First();”, child object’s foreign key property is still the original one even its navigation property for the ParentTable is changed.   So, the foreign key property’s extensibility methods won’t be fired.   After the SubmitChanges() is called, the modified properties will sync up the changes.

     

    If you have any questions, please feel free to let me know.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by derski Tuesday, February 9, 2010 3:31 PM
    Tuesday, February 9, 2010 2:50 AM
    Moderator

All replies

  • Hello Chris,

     

    How are you?   I am very glad to see you here again!

     

    We don’t have the **Changing or **Changed extensibility methods for navigation properties.   Once the navigation properties are modified, we use the entity’s PropertyChanged or PropertyChanging events to track.  

    ===============================================================================

    var child = db.ChildTables.First();

    child.PropertyChanged += new PropertyChangedEventHandler(child_PropertyChanged);

    child.ParentTable = db.ParentTables.First();

     

            void child_PropertyChanged(object sender, PropertyChangedEventArgs e)

            {

                MessageBox.Show(e.PropertyName);

            }

    ===============================================================================

    We will get result that it is the “ParentTable” navigation property is changed in the child_PropertyChanged event handler.  

     

     

    For the foreign key properties, they won’t be updated immediately after the navigation properties are modified.  In the above sample codes, after the codes of line: “child.ParentTable = db.ParentTables.First();”, child object’s foreign key property is still the original one even its navigation property for the ParentTable is changed.   So, the foreign key property’s extensibility methods won’t be fired.   After the SubmitChanges() is called, the modified properties will sync up the changes.

     

    If you have any questions, please feel free to let me know.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by derski Tuesday, February 9, 2010 3:31 PM
    Tuesday, February 9, 2010 2:50 AM
    Moderator
  • Thats perfect,
    Thanks a lot for your help.

    Chris
    Tuesday, February 9, 2010 4:06 PM
  • You're welcome, Chris!

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, February 10, 2010 1:12 AM
    Moderator