【问题标题】:How to set a configuration property when using fluent nhibernate?使用流利的nhibernate时如何设置配置属性?
【发布时间】:2009-06-09 23:25:01
【问题描述】:

特别是,我想设置current_session_context_class。我知道如何在 hibernate.cfg.xml 中做到这一点,但是使用纯流利的配置是否有可能?

【问题讨论】:

    标签: nhibernate fluent-nhibernate


    【解决方案1】:

    您可以在FluentConfiguration 实例上使用方法ExposeConfiguration 来访问原始NHibernate Configuration 对象。

    然后,您将可以访问Properties 属性,并且可以添加current_session_context_class

    这是一个伪代码:

    Fluently.Configure()
       .Database(SQLiteConfiguration.Standard.InMemory)
       .ExposeConfiguration(c =>
                            {
                              c.Properties.Add("current_session_context_class", 
                                               typeof(YourType).FullName);
                            })
       //.AddMapping, etc.
       .BuildSessionFactory();
    

    【讨论】:

    • 这对我不起作用,当我调用 GetCurrentSession 时,它仍然会抛出一个异常,告诉我设置属性。
    • 嗯,我的答案现在已经 2 岁了,所以我并没有那么惊讶。不幸的是,我不再使用 FluentNHibernate,而且我不确定我是否可以很快更新我的答案......
    • 不幸的是,这对我也不起作用,我在使用 FlushMode 时遇到了类似的问题,请参阅 stackoverflow.com/questions/52260763/…
    猜你喜欢
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    • 2010-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 2010-11-06
    相关资源
    最近更新 更多