许多示例都主张显式回滚数据库事务,大致如下:
using (var transaction = ...)
{
try
{
// do some reading and/or writing here
transaction.Commit();
}
catch (SqlException ex)
{
// explicit rollback
transaction.Rollback();
}
}
但是,我倾向于这样做:
using (var transaction = ...)
{
// do some reading and/or writing here
transaction.Commit();
}
当异常发生时,我只是依赖于未提交的事务的隐式回滚.
依赖这种隐含的行为有什么问题吗?有没有人有令人信服的理由让我不能这样做?