see http://nhibernate.info/doc/howto/various/changing-values-in-nhibernate-events.html
which links to https://github.com/Buthrakaur/NHListenerTests/blob/master/NHListenerTest/SetModificationTimeFlushEntityEventListener.cs I've used this successfully in the past to implement that type of audit. On Wednesday, March 11, 2015 at 10:40:31 AM UTC-4, JJ BB wrote: > > Hi again, > > I tested with EmptyInterceptor: > > public class TestInterceptor : EmptyInterceptor > { > public override bool OnSave(object entity, object id, object[] > state, > string[] propertyNames, > IType[] types) > { > return base.OnSave(entity, id, state, propertyNames, types); > } > > public override bool OnLoad(object entity, object id, object[] > state, string[] propertyNames, IType[] types) > { > return base.OnLoad(entity, id, state, propertyNames, types); > } > > public override void OnDelete(object entity, object id, object[] > state, string[] propertyNames, IType[] types) > { > base.OnDelete(entity, id, state, propertyNames, types); > } > > public override bool OnFlushDirty(object entity, object id, > object[] currentState, > object[] previousState, string[] > propertyNames, > global::NHibernate.Type.IType[] > types) > { > return base.OnFlushDirty(entity, id, currentState, > previousState, propertyNames, types); > } > } > > > I'm having a similar trouble than IPostUpdateEventListener: OnFlushDirty > previousState is null. Why? > > Cheers > > El dilluns, 9 març de 2015 19:02:05 UTC+1, JJ BB va escriure: >> >> Hi folks, >> >> I'm into a record versioning requirement of all mapped entities (using >> hbm.xml files). >> >> public class User >> { >> public virtual String UserName { get; set; } >> public virtual String Password { get; set; } >> (...) >> public virtual Int32 SysVersion { get; set; } >> } >> >> I'm invoking IPostInsertEventListener from nhibernate.cfg.xml: >> >> <event type="post-insert"> >> <listener class="myEvents.PostInsert, myAssembly /> >> </event> >> >> This is the code: >> >> public class PostInsert : IPostInsertEventListener >> { >> //IPreInsertEventListener >> //public bool OnPreInsert(PreInsertEvent preInsertEvent) >> //{ >> // Correction(preInsertEvent.Entity); >> // return false; >> //} >> >> //internal static void Correction(object entity) >> //{ >> // var sysVersion = >> entity.GetType().GetProperties().FirstOrDefault >> // ( >> // p => p.PropertyType == typeof(Int32) && >> p.Name.ToLower() == "sysversion" >> // ); >> >> // if (sysVersion == null) >> // return; >> >> // sysVersion.SetValue(entity, 1, null); >> //} >> public void OnPostInsert(PostInsertEvent @event) >> { >> //@event.Entity >> >> var sysVersion = >> @event.Entity.GetType().GetProperties().FirstOrDefault >> ( >> p => p.PropertyType == typeof(Int32) && >> p.Name.ToLower() == "sysversion" >> ); >> >> if (sysVersion == null) >> return; >> >> sysVersion.SetValue(@event.Entity, 1, null); >> } >> >> I need centralize sysVersion Insert and Update and then audit both >> operations in an audit table. Code runs sysVersion.SetValue, but, NH does >> not save sysVersion=1 into the table. >> >> Please can you help me ? >> > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/nhusers. For more options, visit https://groups.google.com/d/optout.
