New Posts New Posts RSS Feed: How do I get a "real" HasChanges?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

How do I get a "real" HasChanges?

 Post Reply Post Reply
Author
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 Topic: How do I get a "real" HasChanges?
    Posted: 14-Mar-2011 at 11:08am
No problem. By the way, you do not need to call BeginEdit() in DevForce.
Back to Top
AuerRo View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Mar-2011
Location: Tyrol, Austria
Posts: 21
Post Options Post Options   Quote AuerRo Quote  Post ReplyReply Direct Link To This Post Posted: 14-Mar-2011 at 11:01am
It works indeed! Thank you very much!
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: 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()));
}
Back to Top
AuerRo View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Mar-2011
Location: Tyrol, Austria
Posts: 21
Post Options Post Options   Quote AuerRo Quote  Post ReplyReply Direct Link To This Post 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!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down