Hello Friends,
How are you?? I am facing problem in ADO.NET entity framework. I want
to impliment Rollback functionality using Entity frameowrk. I am trying
to insert record in multiple tables in one transaction using different
contexts. My application scenario is given below:
EntityContainer ec = new EntityContainer();
//Make Entity Object
//Set all values of Entity and Call ec.AddToEntity() object
//Call: ec.SaveChanges();
//Make New Method for Other Entity
--Make New Entity Container object by name ec2.
--Set all values of Entity
--and then SaveChanges of ec2
Now i've problem when ec1 successfully updated the value and if ec2
fails to Save values in table. Then all values from ec1 should also be
Rollback. I am try to solve it by using "TransactionScope()" but it
faiuls to commit changes. Code snippest is given below:
{
using (TransactionScope ts = new TransactionScope())
{
ec1.AddToEntity(newObj);
ec1.SaveChanges();
AddEntity2();
ts.Complete();
}
}
AddEntity2()
{
//Code for ec2 operations
ec2.SaveChanges();
}
When it call ts.complete then it gives exception that: "The transaction has aborted".
Can anyone help us that how i can solve this issue??