如果你有这样的东西:
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/