New Posts New Posts RSS Feed: Detecting changes to a new Entity
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Detecting changes to a new Entity

 Post Reply Post Reply
Author
chuckc View Drop Down
Groupie
Groupie


Joined: 27-Feb-2010
Posts: 54
Post Options Post Options   Quote chuckc Quote  Post ReplyReply Direct Link To This Post Topic: Detecting changes to a new Entity
    Posted: 04-Mar-2010 at 12:23pm
Thanks for the reply, David.

So, it sounds like the EntityAspect property of a DevForce entity just returns the underlying EntityFramework entity.

That seems to imply that the upcoming April version of DevForce that supports Entity Frameworks 4.0 will have the improved self-tracking features that are supposed to be coming in EF4, as discussed here:

http://www.develop.com/entityframework4

Can I get a beta copy of DevForce for EF4?
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: 04-Mar-2010 at 10:43am

EntityAspect.HasChanges() is currently working as designed.

If you want different semantics, you will have to handle it yourself.  For example, if you want to know if an entity has changed since it was initially created, you could add an additional property to the entity such as ChangedAfterCreated.  You would first set the value of this property to false when you created the entity.  You could then add a PropertyChanged event handler to handle the ChangedAfterCreated property.
Back to Top
chuckc View Drop Down
Groupie
Groupie


Joined: 27-Feb-2010
Posts: 54
Post Options Post Options   Quote chuckc Quote  Post ReplyReply Direct Link To This Post Posted: 27-Feb-2010 at 4:39pm
Hopefully this is a simple question to answer.

When creating a new object/Entity, how does one skip attempting to save it if it has not been modified? I'm trying to add some logic into a Saving event handler, but EnityAspect.HasChanges() seems to always return true as soon as an object has been created, even before any properties have been modified.   AcceptChanges() and RejectChanges() seem to have no effect.

Employee e = _manager.CreateEntity<Employee>();
// e.EntityAspect.HasChanges() == true

e.EntityAspect.AcceptChanges();
// e.EntityAspect.HasChanges() == true

e.EntityAspect.RejectChanges();
// e.EntityAspect.HasChanges() == true

The above code behaves the same even when the Employee is created with a simple constructor, e.g. Employee e = new Employee();

Is there some other technique that you recommend?

Thanks.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down