11

如果你有这样的事情:

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 是否也会被回滚?

4

2 回答 2

20

是的。

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

于 2009-12-04T08:06:39.100 回答
7

有关此主题的说明,请参见此处:http://web.archive.org/web/20091012162649/http: //www.pluralsight.com/community/blogs/jimjohn/archive/2005/06/18/11451.aspx .

另外,请注意,这scope1.Dispose是多余的,因为将在声明它scope1的块的末尾自动处理。using

于 2009-12-04T08:05:24.277 回答