I suggest that you use IPost* events for auditing.
And use a child session for saving. Example:

public class AuditEventListener : IPostInsertEventListener
{
    public void OnPostInsert(PostInsertEvent e)
    {
        var audit = new Audit
        {
            CreatedBy = ...
            ...
        };
        e.Session.GetSession(EntityMode.Poco).Save(audit);
    }
}

   Diego


On Mon, May 24, 2010 at 11:38, deejbee <[email protected]>wrote:

> I'm implementing auditing of inserts so I've implemented
> IPreInsertEventListener and it's firing as I would expect however I'm
> trying to create a new Audit record in the same database with details
> of the record that was originally being created (via SaveAndFlush()).
>
> An exception "Collection was modified; enumeration operation may not
> execute." is being thrown and the transaction is rolled back.  I tried
> creating a child session for the audit record but that didn't seem to
> make any difference.  Does anyone have an example how to do this or
> what I might be doing wrong?
>
>        public bool OnPreInsert(PreInsertEvent e)
>        {
>
>            Audit audit = new Audit();
>            audit.CreatedBy = "somename";
>            audit.CreatedDateTime = DateTime.Now;
>            <<others snipped>>
>
>            audit.Save();
>
>            return false;
>        }
>
> Many Thanks
>
> --
> 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]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>

-- 
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.

Reply via email to