Dialect/Driver - Every SELECT I perform, add with(nolock)

后端 未结 4 602
猫巷女王i
猫巷女王i 2020-12-18 17:00

I need to know a way to implement in my system, a Driver or Dialect which, whenever I perform a SELECT in Nhibernate, the SELECT adds the with(nolock) with it. I need that t

4条回答
  •  暖寄归人
    2020-12-18 17:40

    It is possible to modify the sql using an Interceptor and overriding the OnPrepareStatement method, something like this:

    public class AddNoLockHintsInterceptor : EmptyInterceptor
    {
        public override SqlString OnPrepareStatement(SqlString sql)
        {
            // Modify the sql to add hints
    
            return sql;
        }
    }
    

    And here is a way to register the interceptor with NHibernate:

    var session = SessionFactory.OpenSession(new AddNoLockHintsInterceptor());
    

提交回复
热议问题