使用带有 Fluent nHibernate 的 nHibernate 包装器

发布于 2024-08-28 05:37:18 字数 382 浏览 5 评论 0 原文

是否可以使用像这样的包装器和流畅的配置?

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

如果是这样,我将在哪里添加流畅的配置?

另外,这是否适合在 ASP.NET 和 Windows 应用程序中使用? 我打算使用存储库模式,用它来创建我的 nHibernate 会话?

Is it possible to use something like this wrapper with fluent configuration?

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

If so, where would I add the fluent config?

Also, would this be suited to use in both asp.net and windows applications?
I'm planning to use the repository pattern, using this to create my nHibernate session?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情场扛把子 2024-09-04 05:37:18

SessionBuilderGetConfiguration 方法中,而不是

    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的类,例如AspSessionBuilderWinAppSessionBuilder,并为当前项目注入合适的类。您应该使用 Jamie Ide 以及 作为此问题的答案发布来处理上下文,而不是使用 HttpContext。您只需将此行修改

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

为诸如 "call""thread_static" 之类的内容。请参阅 NHibernate Forge wiki 上的此页面,了解不同上下文会话类型的详细说明:

上下文会话@ NHibernate Forge

In the GetConfiguration method in your SessionBuilder, instead of the

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

shown in the page you linked, simply do something like this:

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

Regarding the further inquiry about handling contexts, you'd have two classes inheriting ISessionBuilder, e.g. AspSessionBuilder and WinAppSessionBuilder, and inject the appropriate one for the current project. You should use the strategy outlined by Jamie Ide also posted as an answer to this question to handle contexts instead of using HttpContext. You just simply have to modify this line:

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

to something like "call" or "thread_static". See this page at the NHibernate Forge wiki for a good explanation of the different contextual session types:

Contextual Sessions @ NHibernate Forge

黯然#的苍凉 2024-09-04 05:37:18

是的,您可以使用它,但最好使用 NHibernate 的内置上下文会话管理,而不是自己处理。请参阅我对这个问题的回答。除了更少的编码之外,它还提供了除了 HttpContext 之外的另外两个选项,Call 和 ThreadStatic。

Yes you can use it but it's better to use NHibernate's built-in contextual session management rather than handle it yourself. See my answer to this question. In addition to less coding, it offers two other options in addition to HttpContext, Call and ThreadStatic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文