我的NHibernate配置设置为显示所有交互的sql.因此,我的一些较大的集成测试表现不佳(特别是在生成测试报告时).
有没有办法在运行时关闭ShowSql - 然后以编程方式重新启动它.
您可以在运行时对配置对象使用 SetProperties(),然后从该配置创建 SessionFactory。SetProperties 采用字典作为参数。然后,新的 SessionFactory 将使用新的配置设置。
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();
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请查看文档的这一部分: ISessionFactory 配置
希望能帮助到你。
/埃里克