我的 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();
有关更多信息,请查看文档的这一部分: ISessionFactory Configuration
希望对您有所帮助。
/埃里克
关于c# - 我可以在初始配置后(在运行时)关闭 NHibernate ShowSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/277136/