我有一個Web項目並使用NHibernate的配置文件是這樣的:NHibernate的配置映射文件
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Server=.\sqlexpress;Initial Catalog=afemanager;Integrated Security=no;User=sa;Password=password;</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="show_sql">true</property>
<mapping file="afe-serialization.hbm.xml"/>
<mapping file="afe-view.hbm.xml"/>
</session-factory>
然後,我讀到這樣的配置:
public static ISession GetSession()
{
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
return config.Configure(Path.Combine(HttpContext.Current.Server.MapPath("/"), "App_Data", NHIBERNATE_CFG)).BuildSessionFactory().OpenSession();
}
當它運行時,它的顯示異常:
'/'應用程序中的服務器錯誤。找不到文件'C:\ Program Files (x86)\ Common Files \ Microsoft Shared \ DevServer \ 11.0 \ afe-serialization.hbm.xml'。
我的.hbm文件不在該目錄中。我的問題是如何設置映射文件從App_Data目錄中獲取.hbm文件。
事情是這樣的:
Path.Combine(HttpContext.Current.Server.MapPath("/"), "App_Data", "afe-serialization.hbm.xml")