New Posts New Posts RSS Feed: Object Graph Dirty Detection
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Object Graph Dirty Detection

 Post Reply Post Reply
Author
mdcalhoun View Drop Down
Newbie
Newbie


Joined: 12-Aug-2010
Location: Marlboro, NJ
Posts: 4
Post Options Post Options   Quote mdcalhoun Quote  Post ReplyReply Direct Link To This Post Topic: Object Graph Dirty Detection
    Posted: 15-Dec-2010 at 1:50pm
Hello,
 
I am wondering if there is a way to determine if any object in the graph is in a "dirty" state. I have a View that updates multiple levels of the object graph and want to enable/disable the save button as well as display a warning if closing the view without saving (if dirty).
 
As an example, if the graph looked like:
 
Deal
--Collection of Version Objects
----Collection of Labor Objects
----Collection of Parts Objects
 
I'm looking for something like myDeal.EntityAspect.HasChanges
 
which would return true if Deal, any Version, Any Labor on Any Version, Any Part on Any Version had changes.
 
Thanks,
Matt
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 21-Dec-2010 at 11:22am
Hi Matt,
 
You could try
 
mgr.HasChanges();
 
as the EntityManager is marked "dirty" when any entity that it manages is changed.
 
Also, you could set events on the collections:
 
...
myDeal.Versions.CollectionChanged += MakeItDirty;
myDeal.Labors.CollectionChanged += MakeItDirty;
myDeal.Parts.CollectionChanged += MakeItDirty;
...
 
public void MakeItDirty(object sender, NotifyCollectionChangedEventArgs e) {
  // Make it dirty code
}
 
 
I hope it helps.
   Silvio.
Back to Top
mdcalhoun View Drop Down
Newbie
Newbie


Joined: 12-Aug-2010
Location: Marlboro, NJ
Posts: 4
Post Options Post Options   Quote mdcalhoun Quote  Post ReplyReply Direct Link To This Post Posted: 21-Dec-2010 at 11:46am
Hi Silvio,
 
Thanks for the reply. Unfortunately your suggestions won't work for my situation.
 
I need to know if any changes have been made to a specific object (and all its sub objects), not the whole manager. So, mgr.HasChanges() won't help me here.
 
As for your second suggestion, that helps to let me know if an object is added/removed from the collection. I want to know if any PROPERTY on any object in the graph has been changed. For example, the CollectionChanged event won't fire if I changed a property on one of the version objects contained in the Version collection.
 
I'm hoping there is a better way than to write code to iterate every object on the graph (and all the child objects and all of the child object's children, etc.) and check to see if it has changes.
 
Thanks,
Matt
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 21-Dec-2010 at 9:00pm
Hi Matt,

One solution you could do is manage the EntityChanged event on the EntityManager. You can then find what entity has changed, and if it is in the list of types you are interested in, you can mark your form as dirty. Once you save/cancel you can reset this flag.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down