user1049099
user1049099

Reputation:

NHibernate Event Listener Audit

I am working on a small project that requires an audit trail.

I have hooked into IPostUpdateEventListener and have a basic audit trail working for simple objects.

public class Foo 
{
      public virtual int Id { get; set; }
      public virtual string PropName { get; set; }
      public virtual ISet<Boo> Boos { get; set; }
}

public class Boo
{
      public virtual int Id { get; set; }
      public virtual string PropName { get; set; }
      public virtual Foo Foo { get; set; }
}

When I want to change the foreign key of Boo load in the relevant Foo object and do a SaveOrUpdate - This works fine with the audit trail.

WHen I get the event listener I check for dirty values and the only dirty property will be that Foo object but problem is that the ISet Boos in Foo isn't initiated. so will throw an error of accessing a property that is lazy loaded.

If I change other properties other than entity it works fine, I just can't seem to do it for Properties that are of another object.

Is there a better way to update the parent of the Boo?

As I want to display the display the changed Foo ID in my audit trail to show that the Foreign key changed.

Cheers

Upvotes: 1

Views: 510

Answers (1)

Zote
Zote

Reputation: 5379

You can use Envers! We use it with success.

Upvotes: 1

Related Questions