In our application, during save operation we are data to almost 15 child tables. When some error occurred, we have data discrepancy in tables. So we decided to use TransactionScope. When we use that it gives error saying "Transaction has aborted", StackTrace display following.
at System.Transactions.TransactionStateAborted.BeginCommit(InternalTransaction tx, Boolean asyncCommit, AsyncCallback asyncCallback, Object asyncState)
at System.Transactions.CommittableTransaction.Commit()
at System.Transactions.TransactionScope.InternalDispose()
at System.Transactions.TransactionScope.Dispose()
Our code looks like
using (TransactionScope tScope = new TransactionScope())
{
dataManager.AddFood(food);
if (!ModelState.IsValid)
throw new ApplicationException("Model state is invalid");
if (beingCloned)
food.IsUserFood = false;
dataManager.Save();
if (!food.IsUserFood)
dataManager.GenerateSearchRecords(food.FoodID);
FoodManager foodManager = new FoodManager();
foodManager.CopyFoodToHistory(food);
if (beingCloned)
{
foodManager.CreateUserFoodCopyForClonedFood(food);
HttpPostedFileBase file = ControllerContext.HttpContext.Request.Files["Image"];
if (file != null && file.FileName.Length > 0)
foodManager.UpdateMediaCopyForClonedFood(food, true);
else
foodManager.UpdateMediaCopyForClonedFood(food);
}
tScope.Complete();
}
Thanks in advance