2009-12-04 35 views
6

嵌套事務如果你有服用點是這樣的:用的TransactionScope

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

回答

14

是的。

內部事務註冊在外部事務的相同範圍內,整個事務將回滾。情況就是這樣,因爲您沒有使用TransactionScopeOption.RequiresNew將內部交易註冊爲新交易。