Yes, it's committing.  I've sort of got round this issue by using an
Identity column instead of a GuidComb as it was suggested in another
post that this might be the issue.  However I found that the
PostInsertEvent was then being fired again (until a stack overflow)
but this time with the Audit entity being passed in.  I got round this
by checking that the type of the entity, only creating an Audit object
if it was not.

It still doesn't feel quite right as I thought the chilt session
shouldn't cause the event to fire again.



On May 25, 12:36 pm, Diego Mijelshon <[email protected]> wrote:
> Are you committing the parent transaction?
>
>    Diego
>
> On Tue, May 25, 2010 at 05:06, deejbee <[email protected]>wrote:
>
>
>
> > Thanks Diego, I tried what you suggested (it makes perfect sense) but
> > it doesn't insert the Audit record.  I can see the Audit recordt in
> > the child session but it doesn't commit. I've tried using the various
> > FlushMode options but they don't seem to make any difference either.
>
> > Any suggestions?
>
> > On May 25, 2:28 am, Diego Mijelshon <[email protected]> wrote:
> > > 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]>
> > <nhusers%[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]<nhusers%[email protected]>
> > .
> > > For more options, visit this group athttp://
> > 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]<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 
> athttp://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