nhibernate with more than one database

Asked

Viewed 139 times

2

Hello, I wonder if it is possible to use nhibernate with more than one database, some tables will be in one database and others in another.

How would I do that?

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

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");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.