Hi,
I am Made Some small Modifications to the NHibernate
Code. Needed Help as to if I am Going in the Right
Direction. I would also Highly appreciate any
Critsisims or Suggestions. Pls also Let Me Know if
This would affect the Exisisting Code in Anyway.
Problem Statement: I needed Dynamic Updates to Work
even If I dont Load the Object in the same session.
Solution:
I will be creating an IClass Interface. This will have
One function called GetDirtyColumns.
All the Entity class Files implement this interface.
Apart from all Properties Entity Class Files will also
have a bool array which will keep a track of all
Changed Properties. This can be done by modifying the
Set Funtion of all Properties.
Now I will pass this array to the EntityPersister
Class. This will now work as Dynamic Update Currently
works.
For My modified version of updatw kindly have alook
at the attached Text File.
Regards
Prasanth Kumar
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
public override void Update( object id, object[ ] fields, int[ ] dirtyFields,
object[ ] oldFields, object oldVersion, object obj, ISessionImplementor session
)
{
//note: dirtyFields==null means we had no snapshot, and we couldn't get
one using select-before-update
//oldFields==null just means we had no snapshot to begin with (we might
have used select-before-update to get the dirtyFields)
bool[ ] propsToUpdate;
SqlString updateString;
if( UseDynamicUpdate && dirtyFields != null )
{
propsToUpdate = GetPropertiesToUpdate( dirtyFields );
updateString = GenerateUpdateString( propsToUpdate, oldFields );
//don't need to check property updatability (dirty checking
algorithm handles that)
}
else
{
//This will happen if Dynamic Update is set True and Dirty
Field are NULL.
//ie: Object not loaded in the same session.
//The Only Flip side of this is if all Fields are NULL then the
Object throws an Error.
if(UseDynamicUpdate)
{
//This is a IClass Interface. Typecasting the Object to
the IClass Interface.
IClass entity = (IClass)obj;
//Geting a list of Dirty Properties.
propsToUpdate = entity.getDirtyProperties();
//Genrating the Update string.
updateString = GenerateUpdateString( propsToUpdate,
oldFields );
}
else
{
propsToUpdate = PropertyUpdateability;
updateString = SqlUpdateString;
}
}
Update( id, fields, oldFields, propsToUpdate, oldVersion, obj,
updateString, session );
}