Does the Transaction object automatically rollback on dispose?
I notice plenty of code examples which do this:
Transaction transaction = new Transaction(...);
try
{
// .. entity modify ...
// .. entity save ...
transaction.Commit();
}
catch(Exception e)
{
transaction.Rollback();
throw e;
}
finally
{
transaction.Dispose();
}
I would prefer to use:
using( Transaction transaction = new Transaction(...) )
{
// .. entity modify ...
// .. entity save ...
transaction.Commit();
}
Purely aesthetic and less-typing point of view and to let the 'using' catch an exception then rollback, dispose and re-throw.
Or am I going mad, and it's getting late?