In your case (not in all cases of Audit) you should use the PreUpdateEvent and change the State.
2009/2/27 Graham Bunce <[email protected]> > > All, > > I'm trying out the Event Listeners to write to an Audit table (pretty > common idea!) in 2.0.1.GA. > > My class is as follows: > > public class SaveOrUpdateEventListener : > ISaveOrUpdateEventListener > { > #region ISaveOrUpdateEventListener Members > > public void OnSaveOrUpdate(SaveOrUpdateEvent @event) > { > IEntity entity = @event.Entity as IEntity; > if (entity != null) > { > if (string.IsNullOrEmpty > (Thread.CurrentPrincipal.Identity.Name)) > { > entity.UpdatedBy = "Unknown"; > } > else > { > entity.UpdatedBy = > Thread.CurrentPrincipal.Identity.Name; > } > entity.UpdatedTimestamp = DateTime.Now; > } > } > > #endregion > } > > and its wired into the cfg as follows > > <event type="save"> > <listener > class="Intellident.Core.Repository.NHibernate.SaveOrUpdateEventListener, > Intellident.Core.Repository.NHibernate" /> > <listener > class="NHibernate.Event.Default.DefaultSaveOrUpdateEventListener"/> > </event> > > When I run the code, it all hooks in correctly. > > I do an Add of a new object but when I hit the Flush I get a > StateStateException. Presumably because the code updates the > UpdatedTimestamp and UpdatedBy fields. When I remove the listener > everything works fine. > > Presumably I'm missing something but there isn't alot of help about on > the internet! > > Any ideas - thanks > > > > > > -- Fabio Maulo --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
