nhibernate配置多个数据库

时间:2011-10-20 13:13:47

标签: database nhibernate configuration

我有这个配置

 var config = new Configuration().Configure(path);
                config.AddAssembly(Assembly.GetCallingAssembly());
                _factory = config.BuildSessionFactory();

和nhibernate.cfg.xml文件

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
  <session-factory name="ServiceCenter.DataAccess">
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">
      Data Source=.\SQLEXPRESS;Initial Catalog=111;User Id=111;Password=111;
    </property>
    <property name="show_sql">false</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>

  </session-factory>
</hibernate-configuration>

我想要2个连接字符串。我尝试添加第二个连接字符串和第二个 配置文件中的session-factory,但它不正确。

2 个答案:

答案 0 :(得分:0)

这个名为NHibernate-X-Factories的扩展很好。看看这个答案:Configure NHibernate hibernate.cfg.xml file to have more connection strings

答案 1 :(得分:0)

这里有一个很好的资料here