Print Page | Close Window

Object Graph Dirty Detection

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2379
Printed Date: 03-Feb-2026 at 8:44am


Topic: Object Graph Dirty Detection
Posted By: mdcalhoun
Subject: Object Graph Dirty Detection
Date 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



Replies:
Posted By: sbelini
Date 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.


Posted By: mdcalhoun
Date 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


Posted By: smi-mark
Date 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.




Print Page | Close Window