I did think of this option but like to keep this all in my application the solution works nicely and I think I will stick with it for now.
Cheers Stefan On Thu, Dec 18, 2008 at 9:17 PM, Fabio Maulo <[email protected]> wrote: > In this case I prefer a <generated> value by a trigger. > > 2008/12/18 Stefan Sedich <[email protected]> >> >> Hello, >> >> I am setting date last modified audit on an entity, I implement an >> IAuditableEntity interface and use a helper to set the date modified: >> >> public override bool OnFlushDirty(object entity, object id, object[] >> currentState, object[] previousState, string[] propertyNames, >> global::NHibernate.Type.IType[] types) { >> >> if >> (typeof(IAuditableEntity).IsAssignableFrom(entity.GetType())) { >> >> // If entity is auditable as this is only an update >> set the last modified date. >> SetValue(propertyNames, currentState, item => >> item.LastModified, DateTime.Now); >> >> } >> >> return false; >> } >> >> >> Type safe helper: >> >> public void SetValue<T>(string[] propertyNames, object[] state, >> Expression<System.Func<IAuditableEntity, T>> propertyExpression, T >> value) { >> >> var memberExpression = propertyExpression.Body as >> MemberExpression; >> if (memberExpression == null) >> throw new ArgumentException("The member expression was >> not a valid member expression."); >> >> string name = memberExpression.Member.Name; >> int index = propertyNames.ToList().IndexOf(name); >> >> if(index == -1) >> throw new >> InvalidOperationException(string.Format("Property {0} does no exist on >> entity.", name)); >> >> state[index] = value; >> >> } >> >> >> Now the question is, I saw that you must set the current state and not >> the entity directly why would >> >> var ent = entity as IAuditableEntity; >> ent.LastModified = DateTime.Now; >> >> Not work properly or will it be fine to do this? >> >> >> >> Thanks >> >> -- >> Stefan Sedich >> Software Developer >> http://weblogs.asp.net/stefansedich >> >> > > > > -- > Fabio Maulo > > > > -- Stefan Sedich Software Developer http://weblogs.asp.net/stefansedich --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
