New Posts New Posts RSS Feed: Capturing Changes
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Capturing Changes

 Post Reply Post Reply
Author
jipock View Drop Down
Newbie
Newbie
Avatar

Joined: 08-Dec-2010
Location: Cherry Hill, NJ
Posts: 39
Post Options Post Options   Quote jipock Quote  Post ReplyReply Direct Link To This Post Topic: Capturing Changes
    Posted: 25-Apr-2011 at 9:55am
Good Afternoon,
 
I'm looking to expand my application to perform some better logging. One thing I've done is implement a Log Writer in the Save Interceptor and this will work fine.
 
Right now, however, I'm trying to write entity changes to the database  (think "User Name / Change Type / Before / After"). The User Name is easy enough, as is the change type (EntityState). But, I'm trying to capture Before and After now.
 
If I have an entity, say, "Property", that appears in a call to the EntityManager.FindEntities(EntityState.Modified) method, I get a collection of entities back. But, how is the best way to determine if the "Address" field or the "Phone Number" field has been modified? And, if I can determine it, is there a way to get a before and after state?
 
Looking through the documentation didn't give an answer, and I thought that since DevForce has a "Reject Changes" function on the Entity Manager, it MUST be saved somewhere.
 
Any help would be appreciated.
 
-Jason
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: 25-Apr-2011 at 11:34am
Hi jipock,
 
You could check which property was changed in the PropertyChanged event:
 
     var order = _mgr.Orders.GetFirstOrDefault();
     order.PropertyChanged += (o, e) => {
        _propertyChanged = e.PropertyName;
      };
 
Or you can compare compare the Current and Original property values of an entity to determine what has changed.
To get the Current and Original values you can use GetValue():
 
     var original = order.EntityAspect.GetValue("Freight", EntityVersion.Original);
     var current = order.EntityAspect.GetValue("Freight", EntityVersion.Current);
 
 
  Silvio.
Back to Top
jipock View Drop Down
Newbie
Newbie
Avatar

Joined: 08-Dec-2010
Location: Cherry Hill, NJ
Posts: 39
Post Options Post Options   Quote jipock Quote  Post ReplyReply Direct Link To This Post Posted: 25-Apr-2011 at 12:11pm
Much thanks, Silvio.
 
-J
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down