WCF RIA HasChanges for EntityFramework

I am currently converting some code from Silverlight / WCF RIA Services to WPF / Entity Framework. The codebase made extensive use of the HasChanges property of the RIA domain context. The view is tied to this property to determine button states. For example, a form is bound to this HasChanges property, and whenever a user changes a property of any object inside a DomainContext , HasChanges will become true, and the Save and Discard buttons will turn on.

After some research, it is obvious that EF does not have an equivalent HasChanges property on an ObjectContext . Does anyone have any clever ideas on how to duplicate this functionality inside the Entity Framework?

I believe that these would be important functions for such a property:

  • This new property HasChanges becomes true whenever any property of any object loaded in the ObjectContext changes.
  • HasChanges will become false whenever the SaveChanges method successfully ObjectContext .
  • The HasChanges property throws a PropertyChanged event in which the view is caught to update the state of the buttons, etc.

Does anyone have any ideas? Maybe a custom EntityObject ADO.NET generator?

+4
source share
1 answer

I had the same problem. The solution is not entirely perfect, but it works. Also note that I'm using Self Tracking Entities in a WPF application.

To check for changes

  • Create Context Instance
  • ApplyChanges () from model to context
  • Check context .HasChanges ()

  using (var context = new MyEntities()) { context.MyTable.ApplyChanges(myTableInstance); return context.HasChanges(); } 

This works well even for graphing objects.

0
source

All Articles