Hi all,
Can anyone post if this approach has any problems? I have implemented it with various NHibernate sessions (to different DBs) inside the transactionScope, and it works!
BUT i have some questions:
1) Why you have to flush after each operation? I've tried without flushing, and it works too.
2) If I try to control transactions with nHibernate also, it doesn't work (because the sessions doesn't disconnect, see DisconnectCurrentSession - DisconnectCurrentSessions in my case) has anyone had the same problem? I must rely the transactions only on System.Transactions??
Here's my code:
Code:
using (TransactionScope scope = TransactionScopeWorker.GetNewScope(TransactionScopeOption.Required))
{
try
{
IDAOFactory daoFac = new TFDaoFactory();
IClienteDao cDao = daoFac.GetClienteDao();
IContactoDao conDao = daoFac.GetContactoDao();
ContactoDN con = new ContactoDN("Manolo2", "El del Bombo2");
conDao.Save(con);
ClienteParticular cp = new ClienteParticular("10.101.011-A", "Paquita", "Rico");
cDao.Save(cp);
// Commenting this line doesn't matter to me! It works the same way! Why?
//NHibernateMultiSessionManager.Instance.FlushAllSessions();
//Create an error (division by cero)
//int i = 1;
//i -= 1;
//double d = 2 / i;
scope.Complete();
}
catch (Exception)
{
throw;
}
}
TransactionScopeWorker is very similar to the one specified here... the differences in the whole code are just to mantain different sessions pointing to different DBs.... If you have any doubts, please tell me and i'll post more code...
THX in advance....
Mahouri.