用的TransactionScope嵌套事务 [英] Nested Transactions with TransactionScope

查看:333
本文介绍了用的TransactionScope嵌套事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于用的TransactionScope嵌套事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆