Somedeveloper
Somedeveloper

Reputation: 867

How can i configure fluent nHibernate connection properties

Can someone tell he how i can setup my fluent nhibernate connection to always connect as follows

this is what i have at the moment

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

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

thanks Niall

Upvotes: 0

Views: 510

Answers (1)

Carlos Cocom
Carlos Cocom

Reputation: 932

Well your can customize that in DriverConnectionProvider. Custome properties how set numer... etc is for session so you could do it using 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.

References Nhibernate 3.0 cookbook

Upvotes: 1

Related Questions