There are multiple similar questions on StackOverflow. Refer this, this and this.
You must be creating two SessionFactory
and ISession
instances, one for each database. Further, you should use TransactionScope
and wrap your database actions against multiple databases in it.
Following code is copied from answer by "Ricardo Peres" for one of the questions above:
using (TransactionScope tx = new TransactionScope())
{
using (ISession session1 = ...)
using (ITransaction tx1 = session.BeginTransaction())
{
...do work with session
tx1.Commit();
}
using (ISession session2 = ...)
using (ITransaction tx2 = session.BeginTransaction())
{
...do work with session
tx2.Commit();
}
tx.Complete();
}