I'm currently converting some code over 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 would bind to this property to determine button states. For example, a form would bind to this HasChanges property, and whenever the user changed any property of any entity inside the DomainContext, the HasChanges would become true and the Save and Discard buttons would become enabled.
After doing some research, it is apparent that EF does not have an equivalent HasChanges property on the ObjectContext. Does anyone have any clever ideas on how one would go about duplicating this functionality inside of Entity Framework?
I suppose these would be the important features for such a property:
- This new HasChangesproperty would become true whenever any property of any entity loaded into theObjectContextchanges.
- The HasChangeswould become false whenever theSaveChangesmethod is successfully called on theObjectContext.
- The HasChan开发者_Go百科gesproperty throws aPropertyChangedevent which the view would catch in order to update button states / etc.
Anybody have any ideas? Maybe a custom ADO.NET EntityObject Generator?
I had the same issue. The solution isn't quite ideal, but it works. Also note that I'm using Self Tracking Entities within a WPF application.
To check for changes
- Create an instance of the context
- ApplyChanges() from the model to the context
- Check context.HasChanges()
    using (var context = new MyEntities())
    {
        context.MyTable.ApplyChanges(myTableInstance);
        return context.HasChanges();
    }
This works well, even for a graph of objects.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论