locked
ChangeInterceptor: How do I get the fields which have been changed? RRS feed

  • Question

  • Is it possible in the ChangeInterceptor to check which fields that has been changed?

    The user should only be able to update certain fields, so I would like to check whether other fields has been changed before saving.

    Thanks

    Henrik

    Friday, August 6, 2010 10:02 AM

Answers

  • I have figured it out myself. I have found no way of doing it the the change interceptor, but I have instead overriden the SaveContext method on ObjectContext.  Here I have access to the ObjectStateManager which I can use to retrieve an ObjectStateEntry. This class has a method called GetModifiedProperties which contains the modified properties.

    Thanks

    Henrik.

    Tuesday, August 10, 2010 7:23 PM

All replies

  • The .Net framework client today sends all the properties, irrespective of whether they are changed or not. The only think i can think of is to add update triggers in your database, and make sure these columns are not updated. You might have to compare the value before you fail, since the same value might be set again and again, because of the client behavior mentioned above.

    Cannot think of any other good way than this. Hope this helps.

    Thanks

    Pratik

     


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, August 9, 2010 5:29 PM
    Moderator
  • I have figured it out myself. I have found no way of doing it the the change interceptor, but I have instead overriden the SaveContext method on ObjectContext.  Here I have access to the ObjectStateManager which I can use to retrieve an ObjectStateEntry. This class has a method called GetModifiedProperties which contains the modified properties.

    Thanks

    Henrik.

    Tuesday, August 10, 2010 7:23 PM
  • Since the WCF data services client sends all the properties, doesn't the state entry tell you that all the properties are modified? Or does it do a comparision and tell us only the properties whose value are actually changed.

    Thanks

    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, August 11, 2010 5:13 PM
    Moderator
  • It seams to be working fine :-) The GetModifiedProperties only returs the properties which have been changed.

    Thanks

    Henrik

    Thursday, August 12, 2010 9:03 AM