views:

18

answers:

1

Hi, i've hooked up logging in my application to automatically log changes to certain entities using event listeners. This works great but for some of the properties withing the entities i'm logging i don't wish to insert a log if only a change is made to that property. These properties are decorated with the IgnoreLoggingAttribute attribute. Here is what i have so far:

public void OnPostUpdate(PostUpdateEvent @event)
{
    var session = @event.Session.GetSession(NHibernate.EntityMode.Poco);

    if (@event.Entity is User)
        session.SaveOrUpdate(new UserLog((User)@event.Entity));
    ...
}

The @event exposes 2 properties which are called State and OldState. I can use this to check for changes however i can't pull out the properties i'm interested in since these are simply an object arrays. I figured i could use some reflection to get the all the indexes (for any properties with the IgnoreLoggingAttribute) and match them up with the ones in the object array. So far i have come up with:

var properties = typeof(User).GetProperties().Where(p => p.GetCustomAttributes(typeof(IgnoreLoggingAttribute), false).Count() > 0);

The problem now is it doesn't give me the index of the property against the original entity. I also need to make sure this matches the appropriate index from the @event.State and @event.OldState properties (which both seem to ignore certain properties).

I'd really appreciate it if someone could help. Thanks

A: 

Have you seen this Can I tell if a property is dirty using nhibernate??

Iain