New Posts New Posts RSS Feed: Detecting that there are changes that need to be saved
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Detecting that there are changes that need to be saved

 Post Reply Post Reply
Author
leeatkinson View Drop Down
Newbie
Newbie


Joined: 01-Jul-2010
Posts: 17
Post Options Post Options   Quote leeatkinson Quote  Post ReplyReply Direct Link To This Post Topic: Detecting that there are changes that need to be saved
    Posted: 03-Sep-2010 at 8:55am
Hi

I have a button that I use to save changes in the entity manager. I want to disable this button when there are no entities to save. However, there doesn't seem to be a HasChangesChanged event, so I've tried EntitytChanged event, and filtering on the Action being EntityAction.Change. However, this seems to say that there are changes when there hasn't been.

entityManager.EntityChanged += (s, e) => { this.HasChanges = (e.Action == EntityAction.Change); };
entityManager.Saved += (s, e) => { this.HasChanges = false; };
However, this doesn't work as it reports that there are changes when there aren't.
Is there a better way to do this?
Lee
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 03-Sep-2010 at 9:25am
Use the HasChanges method of the EntityManager
 
Determines whether the EntityManager cache has any changes that have not yet been persisted to the backend data source.
Back to Top
leeatkinson View Drop Down
Newbie
Newbie


Joined: 01-Jul-2010
Posts: 17
Post Options Post Options   Quote leeatkinson Quote  Post ReplyReply Direct Link To This Post Posted: 03-Sep-2010 at 9:53am
Sorry, perhaps I wasn't clear - what I want is an event that is raised when HasChanges() has changed.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 03-Sep-2010 at 3:15pm
There isn't a HasChanges event on the EntityManager, but you should be able to use the EntityChanged event for what you want.  I'm surprised that you're seeing EntityAction.Change events raised when there aren't any actual changes - do you have more information on when you see this?  You should, though, be careful in setting your HasChanges flag - right now you'll be setting it on and off more frequently than you want, since this event is raised for quite a few different actions. 
 
Something similar to the following should work, so that you're not setting the flag off for other actions, and optionally also testing the EM for changes if you find that Change actions are fired erroneously.   I should note that Add and Delete activities will fire both the Add/Delete action and the Change action, so checking only for Change should be sufficient.    
 
entityManager.EntityChanged += (s, e) => {
  if (this.HasChanges) return;
  this.HasChanges = e.Action == EntityAction.Change && entityManager.HasChanges();
};
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down