1

我想获得关于管理以下请求的最佳方法的意见。我有一个MVC应用程序项目,以及一个DomainModel项目。 NHibernate映射和hibernate.cfg.xml位于MVC应用程序中引用的DomainModel项目中。这通常会正常工作,因为我所有的数据访问都会通过NHibernate连接。如何管理单独项目的NHibernate和Asp.NET MVC ConnectionStrings

问题是我正在使用Sql成员资格提供程序,所以需要从Asp.net MVC中直接访问连接字符串。

问题1

有没有人有这个问题前,这将是最干净的解决方案?我想确保我只有一个存储连接字符串的地方。

问题2

我将如何配置NHibernate的有两个单独的连接,用于调试和与代码

#if DEBUG 
connection = configuration.Properties[/*DEBUGconnectionstring-hibernate.cfg.xml*/] 
#else 
connection = configuration.Properties[/*RELEASEconnectionstring-hibernate.cfg.xml*/] 
#endif 

目前唯一有效的属性connection.connection_string释放。

你会如何解决这个问题?

谢谢。

回答

2

也许将您的nhibernate配置信息移动到您的项目配置文件(app.config或web.config)可解决您的问题。例如,我在一个解决方案中有两个项目。其中之一是WCF服务,另一个是赢得服务。我有以下连接信息seperatly每个项目配置文件。

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> 
    <session-factory> 
     <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> 
     <property name="dialect">NHibernate.Dialect.Oracle10gDialect</property> 
     <property name="default_schema">DUMMY</property> 
     <property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property> 
     <property name="connection.connection_string">Data Source=SRV_OLDEV;User Id=USRdummy;Password=USRdummy;</property> 

     <property name="proxyfactory.factory_class"> 
     NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu 
     </property> 
     <property name="show_sql">true</property> 
    </session-factory> 
    </hibernate-configuration> 
0

我使用FNH将代码中的连接设置为NH。这可能不适合你,但如果是这样,这个问题就会消失。