【问题标题】:How can I use the NHibernate Configuration class with Fluent NHibernate如何将 NHibernate 配置类与 Fluent NHibernate 一起使用
【发布时间】:2009-11-19 12:23:36
【问题描述】:
即使在部署了我的代码之后我也想保持灵活性,所以我喜欢使用 hibernate.cfg.xml 文件来配置 NHibernate。现在,我打算使用 Fluent NHibernate 来完成我所有的 Class => Table 映射。有没有办法可以使用旧的 NHibernate 配置类来配置 Fluent NHibernate?
【问题讨论】:
标签:
nhibernate
fluent-nhibernate
nhibernate-configuration
【解决方案2】:
好吧,所以这显然是我的错。我尝试将 NHibernate Configurtion 对象传递给 Fluently.Configure() 方法,但我的代码抛出了各种错误。问题出在 NHibernate 'Fluent-NHibernate' 用户的版本上。我不知道代理工厂类属性现在是强制性的。因此,我的 hibernate.cfg.xml 文件缺少该属性。奇怪的是,Fluent NHibernate 没有给我任何线索。当我尝试使用普通的 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>