c# - 使用 TransactionScope 的嵌套事务

标签 c# .net transactionscope

如果你有这样的东西:

IBinaryAssetStructureRepository rep = new BinaryAssetStructureRepository();
var userDto = new UserDto { id = 3345 };
var dto = new BinaryAssetBranchNodeDto("name", userDto, userDto);
using (var scope1 = new TransactionScope())
{
    using(var scope2 = new TransactionScope())
    {
        //Persist to database
        rep.CreateRoot(dto, 1, false);
        scope2.Complete();
    }
    scope1.Dispose();
}
dto = rep.GetByKey(dto.id, -1, false);

内部的TransactionScope scope2也会回滚吗?

最佳答案

是的。

内部事务在外部事务的同一范围内注册,整个事务将回滚。情况就是这样,因为您没有使用 TransactionScopeOption.RequiresNew 将内部事务注册为新事务。

关于c# - 使用 TransactionScope 的嵌套事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1845517/

相关文章:

c# - 带有 P-256 的 ECDH 使用静态 key 生成共享 key bouncy caSTLe c#

c# - 使用对象初始化构造的嵌套事务范围导致错误

c# - 忽略 TransactionScope 中的 SqlTransaction.Commit

c# - WPF 投影大小

c# - MVC 上的 IdentityServer : What is Audience refering in AddJwtBearer

c# - Resharper 为 ReactiveUI 的 ReactiveObject 创建自定义重构

c# - Linq 查询组合两个或三个表达式

.net - "SAP Connector for .NET": Generate proxies without Visual Studio 2003

c# - 我的网站是否已关闭、无法正常工作或出现错误?

c# - 具有可重复读取隔离的事务中的数据是否可能发生变化?