locked
Detecting changes to a linked entity RRS feed

  • Question

  • Data Services entity classes are generated using DataSvcUtil from an EDM are partial classes.  They include a definition partial methods in the format OnXChanging and OnXChanged.  For example, if there is an entity property called FirstName, there will be partial methods named OnFirstNameChanging and OnFirstNameChanged.  These methods are called from the setter for the property.  This architecture allows you to manually create a partial class with the same name in a separate file to accompany the automatically generated entity classes, and then implement the OnXChanging/Changed methods to track changes to those values.

     

    Linked entities are also implemented as properties.  For example, if the entity is Employee and Employee objects link to an entity called Group, the Employee entity will have a Group property as well.  However, DataSvcUtil does not define OnGroupChanging and OnGroupChanged partial methods.  Therefore you can't track changes to linked entities in the same way you can simple entity properties.

     

    Is there a reason why linked entities aren't handled the same way as entity properties?  Is there a suggested workaround?  I need to track all property changes to my entity using INotifyPropertyChanged, including changes to linked entities.  (This is related to binding entities into a Silverlight DataGrid).  It appears that I'm going to have to modify the file created by DataSvcUtil to add this support, which is obviously a bad idea that is likely to result in bugs being introduced as the data model changes over time.

     

    Thanks,

     

    David Cater

    Thursday, October 16, 2008 3:53 PM

Answers

  •  

    Thanks for reporting this. We are looking at various options to make things better in V2 - something like template based code gen, etc.

     

    We did miss generating the OnXChanged methods on reference navigation properties (Providing them for collections is difficult, until we write our own collection classes). The only workaround for now is to write it ourselves in our own partial class (not the one generated by code gen).

     

    Thanks

    Pratik

    Monday, October 20, 2008 5:30 PM
    Moderator

All replies

  •  

    Thanks for reporting this. We are looking at various options to make things better in V2 - something like template based code gen, etc.

     

    We did miss generating the OnXChanged methods on reference navigation properties (Providing them for collections is difficult, until we write our own collection classes). The only workaround for now is to write it ourselves in our own partial class (not the one generated by code gen).

     

    Thanks

    Pratik

    Monday, October 20, 2008 5:30 PM
    Moderator
  • How would you add it to a partial class?  The only way I could figure out to raise the PropertyChanged event was to add it directly to the setter in the class generated by code gen.  I would much prefer to put it in my manually created partial class, but I don't understand exactly what you are suggesting I do to accomplish that.

     

    Thanks,

     

    David

     

    Monday, October 20, 2008 5:35 PM