Ok sorry for the long subject name…
If I do the following:
using (var transaction = session.BeginTransaction())
{
// do something
transaction.Commit();
}
If my do something caused an exception, would it auto rollback, or do I need to explicitly check for this like below:
using (var transaction = session.BeginTransaction())
{
try
{
// do something
transaction.Commit();
}
catch (Exception)
{
transaction.Rollback();
}
}
It’s a safe assumption that the transaction will be rolled back if the commit fails in a using block.
ITransactionwraps an ADO.NET transaction behind the scenes, so it depends on the provider specific implementation. TheDisposemethod in the source code I checked (2.1) assumes that callingDisposeon the internalIDbTransactionrolls it back.