Print Page | Close Window

Capturing Changes

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=2635
Printed Date: 16-Jun-2026 at 10:09am


Topic: Capturing Changes
Posted By: jipock
Subject: Capturing Changes
Date 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



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


Posted By: jipock
Date Posted: 25-Apr-2011 at 12:11pm
Much thanks, Silvio.
 
-J



Print Page | Close Window