property IsDirty ?

property IsDirty ?

Old forum URL: forums.lhotka.net/forums/t/6879.aspx


martin_s posted on Thursday, April 30, 2009

Can you check which properties of a object are dirty (v3.6.2) ?
We may want to use this to generate SQL update statements including only changed database fields.
Also, is it possible to retrieve the previous value of a dirty property ?

The SQL would be generated in the application server tier of an N-Tier system.

Cheers
Martin.

ajj3085 replied on Thursday, April 30, 2009

There's no built in support for this, but you can create your own implemenation of certain Csla objects that tracks this. I believe JoeFallon1 has done this, a search of the forum should yield the answer.

RockfordLhotka replied on Thursday, April 30, 2009

It is easier in 3.6.x because of the field manager.

However, the default FieldData object may not track per-field dirty state as you'd like, so you may need to create your own IFieldData implementation - which is a fine thing to do.

You can ask the GetFieldData() method on the FieldManager to get access to the individual IFieldData object for each managed property, and that has an IsDirty property. Using this, you can enhance your business class to expose such a value. Something like this:

public bool IsPropertyDirty(IPropertyInfo prop)
{
  return FieldManager.GetFieldData(prop).IsDirty;
}

Again, the default IsDirty implementation is pretty basic, so you may need to create a more powerful IFieldData implementation (and corresponding PropertyInfo<T> subclass).

JoeFallon1 replied on Thursday, April 30, 2009

Here is a good thread:
http://forums.lhotka.net/forums/thread/28073.aspx

Joe

Copyright (c) Marimer LLC