Hi, my goal is to log all changes (INSERT, UPDATE, DELETE) made to the
database. At the moment I use the "state" properties of the event args
from the event listener API of NHibernate.
Unfortunately this doesn't work well if the changed property itself is
another entity or if a user type is used. In these cases I would like
to log the entity's Id/the value of the db columns etc.
But I did not found any data in the event args (IEntityPersister,
ISession, etc.) that contain the original values of the db columns. Is
this actually possible?
Here's a sample where an INSERT operation in handled.
result.DatabaseValues contains the changed data.
private DatabaseOperation CreateInsertOperation(PostInsertEvent
@event, LoggedClassConfiguration entityLoggingConfiguration)
{
string tableName = @event.Persister.QuerySpaces.First();
DatabaseOperation result = ...
object[] newState = @event.State;
for (int i = 0; i < newState.Length; i++)
{
object newValue = newState[i];
PropertyColumnMapping map =
entityLoggingConfiguration.GetMapping(@event.Persister.PropertyNames.ElementAt(i));
if (map == null)
{
continue;
}
result.DatabaseValues.Add(new DatabaseValue
{
NewValue = newValue,
FieldName = map.DatabaseColumnName
});
}
return result;
}
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.