I am adding auditing to an application where I need to add a record to
my entity on a collection of AuditLogEntry:
User
{
IList<AuditLogEntry> Entries {get;set;}
}
I created a listener and in OnPreUpdate I am doing the following:
if (!(evt.Entity is ICanBeAudited))
return false;
ICanBeAudited entity = evt.Entity as ICanBeAudited;
var session = evt.Session.GetSession( EntityMode.Poco );
ICanBeAudited newEntity = (ICanBeAudited)session.Get
(evt.Entity.GetType(), entity.Id );
newEntity.AddAuditEntry(new AuditLogEntry(AuditEvent.Edit,
"Some User", "Update comments...."));
session.SaveOrUpdate( newEntity );
session.Flush();
This approach works and adds the item to the entity, but it is a
little smelly. Is it ok to get another session instance and
saveorupdate the entity at hand in a different session in this manner?
I tried to do it without getting another session but it tells me
"collection x was not processed by flush()"
This collection would only be added to during this listener so I'm
assuming its ok to assume there are not changes to the collection. If
this isn't a recommended approach, then how should I update a
collection on an entity during an OnPreUpdate event?
thanks
Sean
--
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.