转换为 Fluent NHibernate 会话管理器

发布于 2024-09-02 16:00:20 字数 1279 浏览 4 评论 0原文

我正在更改我的应用程序以使用 Fluent NHibernate。我已经创建了 Fluent 映射文件,现在开始配置我的会话管理器。目前,我使用以下代码 -

private ISessionFactory GetSessionFactory()
{
     return (new Configuration()).Configure().BuildSessionFactory();
}

以及我的 hibernate.cfg.xml -

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.InformixDialect1000</property>
    <property name="connection.driver_class">NHibernate.Driver.OleDbDriver</property>
    <property name="connection.connection_string">Provider=Ifxoledbc.2;Password=mypass;Persist Security Info=True;User ID=myid;Data Source=mysource</property>

    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
    <property name="show_sql">false</property>
    <mapping assembly="DataTransfer" />
  </session-factory>
</hibernate-configuration>

有谁知道我如何将其转移到 Fluent?我遇到的问题是配置的数据库部分。

感谢您的任何想法。

I am changing my application to use Fluent NHibernate. I have created my Fluent mapping files and have now moved onto configuring my Session Manager. Currently, I use the following code -

private ISessionFactory GetSessionFactory()
{
     return (new Configuration()).Configure().BuildSessionFactory();
}

Along with my hibernate.cfg.xml -

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.InformixDialect1000</property>
    <property name="connection.driver_class">NHibernate.Driver.OleDbDriver</property>
    <property name="connection.connection_string">Provider=Ifxoledbc.2;Password=mypass;Persist Security Info=True;User ID=myid;Data Source=mysource</property>

    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
    <property name="show_sql">false</property>
    <mapping assembly="DataTransfer" />
  </session-factory>
</hibernate-configuration>

Does anyone know how I could transfer this to Fluent? The problem I have having is with the Database portion of the configuration.

Thanks for any thoughts.

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

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

发布评论

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

评论(2

一身软味 2024-09-09 16:00:20

对于 informix 支持 您需要下载最新的 Fluent nhibernate 二进制文件 (#680为我工作):

private ISessionFactory CreateSessionFactory()
{
    return Fluently.Configure()
        .Database(
            IfxOdbcConfiguration
                .Informix1000
                .ConnectionString("Provider=Ifxoledbc.2;Password=mypass;Persist Security Info=True;User ID=myid;Data Source=mysource")
                .Driver<OleDbDriver>()
                .Dialect<InformixDialect1000>()
                .ProxyFactoryFactory<ProxyFactoryFactory>()
        )
        .Mappings(
            m => m
                .FluentMappings
                .AddFromAssemblyOf<SomePersistentType>()
        )
        .BuildSessionFactory();
}

For informix support you will need to download the latest fluent nhibernate binary (#680 worked for me):

private ISessionFactory CreateSessionFactory()
{
    return Fluently.Configure()
        .Database(
            IfxOdbcConfiguration
                .Informix1000
                .ConnectionString("Provider=Ifxoledbc.2;Password=mypass;Persist Security Info=True;User ID=myid;Data Source=mysource")
                .Driver<OleDbDriver>()
                .Dialect<InformixDialect1000>()
                .ProxyFactoryFactory<ProxyFactoryFactory>()
        )
        .Mappings(
            m => m
                .FluentMappings
                .AddFromAssemblyOf<SomePersistentType>()
        )
        .BuildSessionFactory();
}
苏别ゝ 2024-09-09 16:00:20

jon - 这是我最终使用的 -

return Fluently.Configure()
                .Database(
                    IfxOdbcConfiguration
                        .Informix1000
                        .ConnectionString("Provider=Ifxoledbc.2;Password=password;Persist Security Info=True;User ID=username;Data Source=database@server")
                        .Dialect<InformixDialect1000>()
                        .ProxyFactoryFactory<ProxyFactoryFactory>()
                        .Driver<OleDbDriver>()
                        .ShowSql()
                    )
                .Mappings(m => m.AutoMappings.Add(persistenceModel))
                .BuildSessionFactory();

我不确定你到底在寻找什么,所以让我知道这是否有效。
谢谢

jon - Here is what I ended up using -

return Fluently.Configure()
                .Database(
                    IfxOdbcConfiguration
                        .Informix1000
                        .ConnectionString("Provider=Ifxoledbc.2;Password=password;Persist Security Info=True;User ID=username;Data Source=database@server")
                        .Dialect<InformixDialect1000>()
                        .ProxyFactoryFactory<ProxyFactoryFactory>()
                        .Driver<OleDbDriver>()
                        .ShowSql()
                    )
                .Mappings(m => m.AutoMappings.Add(persistenceModel))
                .BuildSessionFactory();

I'm not sure exactly what you are looking for, so let me know if that works.
thanks

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