开发者

What should I return from an NHibernate Event Listener?

开发者 https://www.devze.com 2022-12-10 13:33 出处:网络
public class MyUpdateListener : IPreUpdateListener { public开发者_运维问答 bool OnPreUpdate(PreUpdateEvent @event)
public class MyUpdateListener : IPreUpdateListener
{
    public开发者_运维问答 bool OnPreUpdate(PreUpdateEvent @event)
    {
           // What do I return from this method - true or false?
    }
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消