Question related to managing trasactions with EF Core:
Does an IDbContextTransaction.Rollback()
have any chance to return an exception, so that it could ever make sense to place it inside a try block?
i.e.
try
{
//...
if(condition)
transaction.Commit();
else
throw methodReturn.Exception;
}
catch (Exception e)
{
try // Does this try make any sense?
{
transaction.Rollback();
}
catch
{
// Log
}
throw e;
}
PD: In this specific situation it is not possible to embed the transaction into a using
statement, so a manual .Rollback()
call is required in the real code.
SqlTransaction.Rollback()
will throw anInvalidOperationException
when the transaction was already committed or was already rolled back (see following link on MSDN: msdn.microsoft.com/en-us/library/zayx5s0h(v=vs.110).aspx ) – bassfader Oct 5 '17 at 13:04