2009-11-19 89 views

回答

2

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

0

好吧,这显然是我的错。我尝试将NHibernate Configurtion对象传递给Fluently.Configure()方法,但是我的代码抛出了各种错误。问题出在NHibernate'Fluent-NHibernate'用户的版本上。我不知道代理工厂类属性现在是强制性的。所以,我的hibernate.cfg.xml文件缺少该属性。这很奇怪,流利的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>