nHibernate with more than one database

1

Hello, I would like to know if it is possible to use nHibernate with more than one database, some tables will be in one bank and others in another.

How would I do this?

And in entity mappings, how would I report that mapping is from a table in a given database?

    
asked by anonymous 15.09.2015 / 15:23

1 answer

2

The mapping of your Entities would be the same, but each DBMS has a configuration file with the connections strings, connection providers, etc ...

EX: Using Postgres:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.PostgreSQLDialect</property>
    <property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property>
    <property name="connection.connection_string">Server=localhost;database=northwind;User Id=postgres;password=123456</property>        
  </session-factory>
</hibernate-configuration>

In the code:

Configuration configuration = new Configuration();

configuration.Configure("conpgsql.config");
    
07.12.2015 / 04:22