我有我的NHibernate配置成功地在我的web.config文件中设置。但是,我也使用ASP.NET Membership,它需要在connectionStrings元素中定义连接字符串。有没有一种方法可以让我的NHibernate配置使用这个值,所以我不需要定义连接字符串两次?web.config中的NHibernate配置 - 使用现有的连接字符串
10
A
回答
16
您可以在NHibernate配置中使用connection.connection_string_name元素。看看here。然后,NHibernate的将名字从web.config文件
获得连接字符串,您需要使用connection.connection_string_name
属性在配置:
<connectionStrings>
<add name="default" connectionString="server=(local);etc." />
</connectionStrings>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.connection_string_name">default</property>
</session-factory>
</hibernate-configuration>
用流利的配置,你可以做以下
ConnectionString(c=>c.FromConnectionStringWithKey("YourConnStrName"))
使用NHibernate配置API,您可以执行以下操作:
var cfg = new Configuration();
cfg.DataBaseIntegration(db =>
{
db.ConnectionStringName = "default";
});
1
只需添加到狡猾的回答,你可以做到这一点使用FluentNHibernate像这样(在你的流利配置):
.ConnectionString(c=>c.FromConnectionStringWithKey("con_development"))
相关问题
- 1. NHibernate配置连接字符串信息
- 2. 如何在我的nhibernate配置中注入连接字符串?
- 3. web.config中的连接字符串安全
- 4. web.config中的连接字符串
- 5. web.config中的sqlite连接字符串
- 6. 如何配置带有FailOver的ODP.NET连接字符串的连接字符串?
- 7. NHibernate的配置错误 - 连接字符串?
- 8. 使用Wix编辑Web.Config连接字符串设置
- 9. 确保连接字符串和web.config中
- 10. 在web.config中加密连接字符串
- 11. 使用msdeploy在web.config中添加新的连接字符串paramters.xml
- 12. 在Web.Config中存储连接字符串的位置?
- 13. web.config中的连接字符串无法连接
- 14. 在C#中使用字符串连接的字符串连接
- 15. NHibernate的/ MySQL的字符串连接
- 16. NHibernate自定义连接字符串配置
- 17. EF迁移没有使用Web配置连接字符串
- 18. NHibernate的连接字符串问题
- 19. 错误的连接字符串NHibernate 3.3
- 20. Web.config和dbml连接字符串
- 21. VB.NET连接字符串(Web.Config,App.Config)
- 22. 简化web.config连接字符串加密
- 23. 从Azure网站连接字符串配置中读取连接字符串
- 24. 在web.config中使用连接字符串进行水晶报告
- 25. 配置连接字符串++/CLI
- 26. SQLite连接字符串配置
- 27. 如何配置NHibernate使用来自<connectionStrings>配置部分的连接字符串
- 28. 没有Web.Config连接字符串的MVC3模型
- 29. 将连接字符串调用到web.config中的另一个连接字符串中
- 30. web.config中的加密和未加密的连接字符串?
完美...谢谢! – 2009-11-17 17:01:11
我希望你引用该解决方案给我提示,因为该页面不再被找到:( – 2010-04-21 11:40:08
http://community.devpinoy.org/blogs/bonskijr/archive/2007/04/08/using-connectionstring-section-in -nhibernate.aspx – Sly 2010-04-21 12:37:55