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);
Will the inner TransactionScope scope2 also be rolled back?
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.
See here for an explanation on this subject: http://web.archive.org/web/20091012162649/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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With