converting to Fluent NHibernate sessionmanager

坚强是说给别人听的谎言 提交于 2019-12-11 06:32:43

问题


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.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/2875127/converting-to-fluent-nhibernate-sessionmanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!