Is it possible to disable NHibernate ShowSQL after initial configuration (at run time)

My NHibernate configuration is configured to display sql for all interactions. Because of this, some of my larger integration tests do not work well (especially when creating a test report).

Is there a way to disable ShowSql at run time - and then enable it again programmatically.

+4
source share
1 answer

You can use SetProperties () for the configuration object at runtime, and then create a SessionFactory from this configuration. SetProperties uses the dictionary as a parameter. Then the new SessionFactory will use the new configuration options.

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(); 

See this section of the documentation for more information: ISessionFactory Configuration

Hope this helps.

/ Erik

+3
source

All Articles