Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I turn off NHibernate ShowSQL after initial configuration (at runtime)

Tags:

c#

nhibernate

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.

like image 784
berko Avatar asked Nov 10 '08 05:11

berko


1 Answers

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

like image 155
Erik Öjebo Avatar answered Oct 12 '22 05:10

Erik Öjebo