views:

40

answers:

1

In the past I used Sub Sonic which has the activerecord pattern baked into the framework. With Sub Sonic it was very easy to find the "dirty" fields on an update. I now have a need to create an audit table in my application that utilizes Entity Framework 4. Is there a comparable feature in EF 4 that will give me the dirty fields?

Thanks for your help!

+2  A: 

You can get similar functionality with what is described in this page at MSDN:

Identity Resolution, State Management, and Change Tracking

Change Tracking -> Change tracking information for the object graph is stored in ObjectStateEntry objects, which are created by the ObjectContext for each attached object. ObjectStateEntry objects store the following information for the entities:

...

The names of the entity's modified properties.

Entity State -> The object context must know the state of an object to save changes back to the data source. ObjectStateEntry objects store EntityState information. The SaveChanges methods of the ObjectContext process entities that are attached to the context and update the data source depending on the EntityState of each object. For more information, see Creating, Adding, Modifying, and Deleting Objects. The following table shows the possible states of an object.

The state of objects inside an object context is managed by the ObjectStateManager. To find out the state of an object, call one of the following ObjectStateManager methods: TryGetObjectStateEntry, GetObjectStateEntry, or GetObjectStateEntries. The State property of the ObjectStateEntry defines the state of the object.

Take a look at this article for more info:

What's New and Cool in Entity Framework 4.0

Leniel Macaferi