代码之家  ›  专栏  ›  技术社区  ›  Alex

使用nHibernate包装器和fluent nHibernate

  •  2
  • Alex  · 技术社区  · 14 年前

    有没有可能使用像这样的包装器和流畅的配置?

    http://jeffreypalermo.com/blog/use-this-nhibernate-wrapper-to-keep-your-repository-classes-simple/

    我计划使用存储库模式,用它来创建我的nHibernate会话?

    2 回复  |  直到 14 年前
        1
  •  4
  •   Community CDub    7 年前

    GetConfiguration 方法 SessionBuilder

        public Configuration GetConfiguration()
        {
            var configuration = new Configuration();
            configuration.Configure();
            return configuration;
        }
    

    显示在链接的页面中,只需执行以下操作:

        public Configuration GetConfiguration()
        {
            return Fluently.Configure()
                .Database(/* your database settings */)
                .Mappings(/* your mappings */)
                .ExposeConfiguration(/* alter Configuration */) // optional
                .BuildConfiguration();
        }
    

    关于处理上下文的进一步查询,您将有两个类继承 ISessionBuilder ,例如。 AspSessionBuilder WinAppSessionBuilder ,并为当前项目注入适当的。你应该使用 Jamie Ide posted as an answer HttpContext . 您只需修改以下行:

    .ExposeConfiguration(x => x.SetProperty("current_session_context_class", "web")
    

    像这样的 "call" "thread_static"

    Contextual Sessions @ NHibernate Forge

        2
  •  1
  •   Community CDub    7 年前