用的TransactionScope嵌套事务嵌套、事务、TransactionScope

由网友(感激有你在丶)分享简介:如果您有服用点是这样的:If you have somehting like this:IBinaryAssetStructureRepository rep = new BinaryAssetStructureRepository();var userDto = new UserDto { id = 3345...

如果您有服用点是这样的:

If you have somehting like this:

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

Will the inner TransactionScope scope2 also be rolled back?

推荐答案

是的。

内部事务就读于外层的相同的范围,整个事情就会回滚。这样的话,因为你没有内部交易注册为一个新的使用TransactionScopeOption.RequiresNew。

The inner transaction is enrolled in the same scope of the outer one, and the whole thing will rollback. This is the case, as you didn't enroll the inner transaction as a new one using TransactionScopeOption.RequiresNew.

阅读全文

相关推荐

最新文章