I have a code like this:
using (TransactionScope transactionScope = new TransactionScope())
{
SetDefaults(products);
// Map the SizeCollectionIds of the products
_dataAccess.MapProductSizes(products);
// Mass update and insert missing parent records to the database
_dataAccess.UpdateParents(products);
// Get ids of parent products that were newly inserted
_dataAccess.PopulateParentProductByParentSku(products);
// Insert children into database
_dataAccess.InsertProducts(products);
// Insert the UPCs into the database
_dataAccess.InsertUPCs(products);
// Get Product Ids of newly inserted records
_dataAccess.PopulateProductIds(products);
// Get just the parent products to insert the brands
List<ParentProduct> parents = (from prod in products
select prod.ParentProduct).Distinct().ToList();
// Insert ParentProductBrand record
_dataAccess.InsertParentProductBrands(parents);
// Insert the custom attribute records
_dataAccess.InsertProductCustomAttributes(products);
transactionScope.Complete();
}
What I intend, is that if an error occurs anywhere in the methods called in the transaction scope, that the transaction is rolled back, but after some testing it seems that this is not the case and my data ends up half baked. Is there something I'm missing? Do I have to wrap the data access calls within the methods themselves in their own TransactionScopes to get this to work?