Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I return from an NHibernate Event Listener?

public class MyUpdateListener : IPreUpdateListener
{
    public bool OnPreUpdate(PreUpdateEvent @event)
    {
           // What do I return from this method - true or false?
    }
}
like image 716
cbp Avatar asked Nov 03 '09 00:11

cbp


1 Answers

I've wondered about this too and was unable to find a definitive answer. So I pulled down the 2.1.1.GA source code and found the answer: returning true from OnPreInsert, OnPreUpdate, or OnPreDelete will veto (i.e. cancel) the respective insert, update, or delete operation. The remainder of the "Pre" listeners return void.

The most common use of IPreInsertListener and IPreUpdateListener is to add record level auditing and for those tasks you should return false.

like image 121
Jamie Ide Avatar answered Nov 03 '22 05:11

Jamie Ide