How to set a default NHibernate CommandTimeOut default value

2.8k Views Asked by At

How can i set an Session.DBCommand.CommandTimeOut NHibernate default value with Castle ActiveRecord?

this config line don't work.

<activerecord >
  <config>
      <add key="command_timeout" value="60"/>
  </config>
</activerecord>

edit: i need some code that changes the CommandTimeOut value when the command is created, what about reflection to set dynamically the value? or PostSharp? someone knows how to?

1

There are 1 best solutions below

0
On

Inside the Fluent Initialise Method you must pass a couple of parameters as so,

public static void Initialise(string connStr)
    {
        _Factory = Fluently.Configure().Database(
                MsSqlConfiguration.MsSql2005
                .ConnectionString(connStr))
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<SessionHandler>())
                .ExposeConfiguration(cfg =>
                {
                    // This will set the command_timeout property on factory-level
                    cfg.SetProperty(NHibernate.Cfg.Environment.CommandTimeout, "180");
                    // This will set the command_timeout property on system-level
                    NHibernate.Cfg.Environment.Properties.Add(NHibernate.Cfg.Environment.CommandTimeout, "180");

                })
                .BuildSessionFactory();
    }

Notice the "180" after each property, this will set the command timeout to be 3 minutes

edit: just noticed you want to do this on a record by record basic, whoops!