NHibernate使用单个配置文件连接到多个数据库 [英] NHibernate using single configuration file to connect to multiple dbs

查看:408
本文介绍了NHibernate使用单个配置文件连接到多个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个配置文件,然后当我创建一个会话时,将hibernate-configuration-> session-factory-> connection.connection_string属性更改为我希望它以编程方式进行的操作。是否有可能?



更新:



我相信我可以像这样做

 配置cfg = new Configuration(); 
cfg.Configure(sessionFactoryConfigPath);

cfg.Properties [connection.connection_string] = ...

我会奇怪,如果这是好的,这是一个不好的方法来处理连接到每个会话的不同数据库?如果是的话,为什么等等。我也想知道你是否可以/如何用.net连接对象打开一个nhibernate会话? 解决方案

使用 ISessionFactory.OpenSession()需要 IDbConnection 的重载。



这就是 Castle的 DifferentDatabaseScope


I'd like to have a single configuration file and then when I'm creating a session change the hibernate-configuration->session-factory->connection.connection_string property to what I want it to be programmatically? Is it possible?

UPDATE:

I believe I may be able to do this like this

Configuration cfg = new Configuration();
cfg.Configure(sessionFactoryConfigPath);

cfg.Properties["connection.connection_string"] = ...

What I would wonder than, if that is ok, Is this a bad way to handle connecting to a different database for each session? if so why etc. I'd also like to know if/how you can open an nhibernate session with a .net connection object?

解决方案

Use the ISessionFactory.OpenSession() overload that takes a IDbConnection.

That's how Castle's DifferentDatabaseScope does it.

这篇关于NHibernate使用单个配置文件连接到多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆