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

转换为Fluent NHibernate sessionmanager

  •  1
  • czuroski  · 技术社区  · 16 年前

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

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

    <?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吗?我遇到的问题是配置的数据库部分。

    2 回复  |  直到 16 年前
        1
  •  3
  •   Darin Dimitrov    16 年前

    为了 informix support latest fluent nhibernate binary (#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();
    }
    
        2
  •  0
  •   czuroski    15 年前

    乔恩-这是我最后用的-

    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();
    

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