如何配置流畅的nHibernate连接属性

时间:2014-11-10 14:50:39

标签: fluent-nhibernate

有人可以告诉他我如何设置流畅的nhibernate连接以始终如下连接

  • SET NOCOUNT ON
  • SET ARITHABORT ON
  • SET NUMERIC_ROUNDABORT ON

这就是我现在所拥有的

            var fluentConfiguration = Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2008.ConnectionString(ConnectionString).ShowSql());

            fluentConfiguration = fluentConfiguration.Cache(c => c
                    .UseQueryCache()
                    .UseMinimalPuts()
                    .ProviderClass<HashtableCacheProvider>());

感谢 尼尔

1 个答案:

答案 0 :(得分:1)

你可以在DriverConnectionProvider中自定义它。 Custome属性如何设置numer ...等用于会话,因此您可以使用driverconnectionproperties

来完成
public class ContextConnectionDriver : DriverConnectionProvider
{
  public override IDbConnection GetConnection()
  {
    var conn = base.GetConnection();
    SetContext(conn);
    return conn;
  }
  private void SetContext(IDbConnection conn)
  {
    string const COMMAND_TEXT = "SET NOCOUNT ON;SET ARITHABORT ON;SET NUMERIC_ROUNDABORT ON;";
    var cmd = conn.CreateCommand();
       cmd.CommandType = CommandType.Text;
       cmd.CommandText = COMMAND_TEXT;           
       cmd.ExecuteNonQuery();
  }
}


Set the NHibernate property connection.provider to <namespace>. ContextConnectionDriver, <assembly>
,to set the namespace and assembly according to the name of your project.

参考Nhibernate 3.0 cookbook