c# - 我可以在初始配置后(在运行时)关闭 NHibernate ShowSQL

标签 c# nhibernate

我的 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/

相关文章:

nhibernate - 在NHibernate 3.2中通过代码将Enum映射为字符串

asp.net - NHibernate StructureMap ASP.NET webform System.OutOfMemoryException

c# - 如何通过沙箱从托管代码调用外部非托管应用程序?

c# - 静态 HttpClient 仍在创建 TIME_WAIT tcp 端口

c# - 解析和验证手机号码的最佳实践

Nhibernate - 如何调试 "Antlr.Runtime.NoViableAltException"?

c# - NHibernate 和 Byte[] 作为主键

c# - 读取单色位图像素颜色

c# - Monitor.Wait 是否确保重新读取字段?

nhibernate - 可以从密码中派生出盐,然后对密码+派生的盐进行哈希处理吗?