tags:

views:

1297

answers:

1

My NHibernate configuration is set to show sql for all interactions. Because of this, some of my larger integration tests are performing poorly (particularly when generating the test report).

Is there a way to turn off ShowSql at runtime - and then switch it back on programmatically.

+3  A: 

You can use SetProperties() on you configuration object at runtime, and then create a SessionFactory from that configuration. SetProperties takes a Dictionary as a parameter. The new SessionFactory will then use the new configuration settings.

        IDictionary<string, string> props = new Dictionary<string, string>();
        props["show_sql"] = "true";

        Configuration config = new NHibernate.Cfg.Configuration();
        config.SetProperties(props);
        config.Configure();
        config.AddAssembly(typeof(User).Assembly);

        ISessionFactory factory = config.BuildSessionFactory();

For more info, check out this section of the docs: ISessionFactory Configuration

Hope it helps.

/Erik

Erik Öjebo
Thanks - I am already using this method to load my initial configuration. I was hoping to be able to modify the ShowSql property without recreating my SessionFactory.
berko