i have to develop a mechanism to check two object properties for changes.
All properties which are needed to check are marked with an attribute.
Atm i
– read all properties from acutal object via linq
– read the corresponding property from old object
– fill an own object with the two properties (old and new value)
In Code the call to the workerclass looks like this
public void CreateHistoryMap(BaseEntity actual, BaseEntity old)
{
CreateHistoryMap(actualEntity, oldEntity)
.ForEach(mapEntry => CreateHistoryEntry(mapEntry),
mapEntry => IfChangesDetected(mapEntry));
}
CreateHistoryMap builds up the HistoryMapEntry which contains the two properties.
CreateHistoryEntry build up the object which is saved to database, the IfChangesDetected check the object for changes.
I have to handle own special application types to generate history values to database (like concatinating list values and so on).
My problem is now, that i have to read the values of the properties twice
– for change detection
– and for the concreate CreateHistoryEntry
How can i eliminate this problem or how can i implement the change tracking scenario with the nice c# 3.5 features?
Thanks a lot.
You could take the approach taken by the CSLA.NET framework, which features undoable objects (and property change tracking for data binding). Its a very clean implementation and is placed in the base class of your business objects, to get the benefit you simply derive.
Link:
http://www.lhotka.net/cslanet/
The classes in question are BusinessBase and UndoableBase – you can also cut out just the change tracking code and leave the rest – although CSLA.NET is well designed, there is a lot of logic embedded into the business objects.