views:

242

answers:

2

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);

Wille the inner TransactionScope scope2 also be rolled back?

+4  A: 

See here for an explanation on this subject: http://www.pluralsight.com/community/blogs/jimjohn/archive/2005/06/18/11451.aspx.

Also, note that the scope1.Dispose is redundant since scope1 will be automatically disposed at the end of the using block that declares it.

Konamiman
+3  A: 

Yes.

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.

Oded