The question asked on following link has a great answer under that as well but my problem starts after that.
Using Transactions or SaveChanges(false) and AcceptAllChanges()?
I tried the code given as per my requirement as follows
MyEntities context1 = new MyEntities();
...
...
// some code for changing the table data in Context 1.
...
MyEntities context1 = new MyEntities();
using (TransactionScope scope = new TransactionScope())
{
context1.SaveChanges(false); // LABEL 1
context2.SaveChanges(false); // LABEL 2
scope.Complete(); // LABEL 3
context1.AcceptAllChanges(); // LABEL 4
context2.AcceptAllChanges(); // LABEL 5
}
Things works fine till line marked with // LABEL 1 However on line // LABEL 2 it fails saying "The underlying provider failed on Open."
NOTE : - Please note that Context1, Context2 are 2 different instance of same Type.
Could anyone help me on this?