代码之家  ›  专栏  ›  技术社区  ›  Khaja Minhajuddin

我怎样用流利的nhibernate来使用nhibernate配置类

  •  1
  • Khaja Minhajuddin  · 技术社区  · 16 年前

    即使在部署了代码之后,我也希望具有灵活性,因此我喜欢使用hibernate.cfg.xml文件来配置nhibernate。现在,我计划使用FluentNHibernate来完成我所有的类=>表映射。有没有方法可以使用旧的nhibernate配置类来配置fluent nhibernate?

    2 回复  |  直到 16 年前
        1
  •  2
  •   James Gregory    16 年前

    是的,如果您使用 fluent configuration API 这个 Configure 方法有一个重载,该重载使用现有的NHibernate Configuration 实例,可以从hibernate.cfg.xml构建。

        2
  •  0
  •   Khaja Minhajuddin    16 年前

    好吧,这显然是我的错。我试图将nHibernate配置对象传递到fluently.configure()方法中,但我的代码抛出了各种各样的错误。问题出在NHibernate的“流利的NHibernate”用户版本上。我不知道代理工厂类属性现在是强制的。因此,hibernate.cfg.xml文件缺少该属性。我是韦德,流畅的尼贝内特没有给我任何线索。当我尝试使用纯NHibernate时,我发现了这个问题。下面是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="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <property name="dialect">NHibernate.Dialect.MsSql2005Dialect,NHibernate</property>
        <property name="connection.connection_string">Data Source=.\SQLEXPRESS;Initial Catalog=SchoolPilot;Integrated Security=True</property>
        <property name="show_sql">true</property>
      </session-factory>
    </hibernate-configuration>
    

    第二版

    <?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="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <property name="dialect">NHibernate.Dialect.MsSql2005Dialect,NHibernate</property>
        <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
        <property name="connection.connection_string">Data Source=.\SQLEXPRESS;Initial Catalog=SchoolPilot;Integrated Security=True</property>
        <property name="show_sql">true</property>
      </session-factory>
    </hibernate-configuration>
    
    推荐文章