配置NHibernate hibernate.cfg.xml文件以具有更多连接字符串 [英] Configure NHibernate hibernate.cfg.xml file to have more connection strings
问题描述
我的客户要求将c#应用程序从"CURRENT"数据库切换到TEST数据库或DEV数据库的可能性. 一次只能激活一个.在菜单文件中,她选择DEV或TEST数据库.
My client asked the posibility to switch from a c# app from the "CURRENT" database to a TEST database or DEV database. Only one can be active at a time. In a menu file she choose DEV or TEST database.
如何配置hibernate.cfg.xml文件以具有更多的连接字符串,例如app.config.
How do I configure hibernate.cfg.xml file to have more connection strings like app.config.
<name="CURRENT" connectionString='User Id=u1;Data Source=CURRENT;Password=...' />
<name="DEV" connectionString='User Id=u1;Data Source=DEV;Password=...' />
<name="TEST" connectionString='User Id=u1;Data Source=TEST;Password=...' />
推荐答案
我可以考虑两种解决方法:
I can think of two ways around this:
一种方法是将NHibernate配置放在* .config文件之外,然后使用FileSystemWatcher类收听此外部文件.您可以动态更改文件内容.
One is to place NHibernate configuration outside *.config file, then listening to this external file using FileSystemWatcher class. You can change the file content dynamically.
另一种方法是同时具有两个NHibernate Configuration对象,然后将其对应的ISession注入到DAO/UnityOfWork/任何东西中
Another way is to have two NHibernate Configuration objects at the same time, and then injecting it's corresponding ISession to your DAO / UnityOfWork / whatever
如果这仅用于开发/测试/生产数据库,我建议两者都反对.最好有三个不同的环境,每个环境都有自己的* .config文件.
If this is just for dev / test / production database, I recommend against both. It's better to have three different environments, each with it's own *.config file .
这篇关于配置NHibernate hibernate.cfg.xml文件以具有更多连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!