Closed yc-2503 closed 7 months ago
class CommandUnitOfWorkBehavior 中 第 54 行
await using var transaction = _unitOfWork.BeginTransaction(); { try { WriteCommandBegin(new CommandBegin(id, commandName, request)); var response = await next(); WriteCommandEnd(new CommandEnd(id, commandName, request)); await _unitOfWork.SaveEntitiesAsync(cancellationToken); await _unitOfWork.CommitAsync(cancellationToken); return response; } catch (Exception e) { WriteCommandError(new CommandError(id, commandName, request, e)); await _unitOfWork.RollbackAsync(cancellationToken); throw; } }
_unitOfWork.SaveEntitiesAsync 中已经执行了CommitAsync ,为何这里还要再执行一遍
_unitOfWork.SaveEntitiesAsync仅当未开启事物时,才会内部开启事物并在执行结束后提交事物。 在外部开启的事物,它是不会提交事物的,因此需要在外部提交事物。
_unitOfWork.SaveEntitiesAsync
class CommandUnitOfWorkBehavior 中 第 54 行
_unitOfWork.SaveEntitiesAsync 中已经执行了CommitAsync ,为何这里还要再执行一遍