How do I get a "real" HasChanges?
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=2556
Printed Date: 29-Jul-2026 at 4:58pm
Topic: How do I get a "real" HasChanges?
Posted By: AuerRo
Subject: How do I get a "real" HasChanges?
Date Posted: 14-Mar-2011 at 2:44am
Hi, quick intro: "real" HasChanges means HasChanges to return False, if changes are undone manually in the UI by the user.
I'm quite new to DevForce, and had the similar question in RIA Services before. As I switched to DevForce (several reasons), ran into the same problem, and thought maybe there is a solution for this already implemented.
Description: - I have an entity (e.g. Employee), on which I activate IEditableObject.BeginEdit() and change a Property (e.g. Property "Surname" from "Auer" to "Auerrr").
- If I call employee.EntityAspect.HasChanges, it returns True, perfect.
- Now I change the Property back to the original value ("Surname" from "Auerrr" to "Auer").
- I want HasChanges to be False, but it isn't.
Questions: - Do I have to compare all entity-properties in my own code, or is there an easy way to achieve a "real" HasChanges?
- If I have to compare them on my own, what would be the best way to achieve this? (I think the easiest way would be to compare the properties with the clone-source created in the implementation of IEditableObject, but: Is there a way to access it?)
- What is the difference between EntityAspect.IsChanged and EntityAspect.HasChanges()?
Thanks for any hint!
|
Replies:
Posted By: smi-mark
Date Posted: 14-Mar-2011 at 8:42am
I've created some extension methods to do this.
It hasn't been fully tested yet but it seems to work on everything I've done so far.
public static bool IsDirty(this EntityWrapper wrapper) { if (wrapper.EntityAspect.EntityState == EntityState.Unchanged) return false;
if (wrapper.EntityAspect.EntityState == EntityState.Added) return true;
return wrapper.EntityAspect.EntityMetadata.DataProperties .Where(p => p.GetValue(wrapper, EntityVersion.Original) != p.GetValue(wrapper, EntityVersion.Current) && !p.GetValue(wrapper, EntityVersion.Original).Equals(p.GetValue(wrapper, EntityVersion.Current) )).Any(); }
public static bool IsDirty(this EntityManager manager) { return manager.GetEntityGroups().Any(g => g.Any(w => w.IsDirty())); }
|
Posted By: AuerRo
Date Posted: 14-Mar-2011 at 11:01am
|
It works indeed! Thank you very much!
|
Posted By: smi-mark
Date Posted: 14-Mar-2011 at 11:08am
|
No problem. By the way, you do not need to call BeginEdit() in DevForce.
|
|