使用相同的架构将NHibernate连接到不同的数据库 [英] Connect NHibernate to different databases with same schema
问题描述
我们正在将数据库分成几个较小的数据库.模式将完全相同,并且我们将控制客户端登录时系统连接到的数据库.如果我未在nhibernate配置中设置连接字符串,则会收到错误消息.我不想为每个数据库创建一个工厂.可以让会话工厂提供一个可以在使用连接字符串之前对其进行设置的会话吗?
We are in the process of splitting our db into several smaller ones. The schemas will be exactly the same and we will control which db the system connects to when the client logs in. I receive an error if I do not set a connection string in my nhibernate configuration. I do not want to create a factory for each db. Is it possible to have a session factory provide a Session that I can set the connection string before using it?
推荐答案
尚未使用它,但是Session.Connection上有一个ChangedDatabase方法.也许行得通吗?
Have not used it but there is a method ChangedDatabase on the Session.Connection. Maybe that would work?
这篇关于使用相同的架构将NHibernate连接到不同的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!