Given a TransactionScope with 2 subsequently opened DbContexts, are changes saved by the first context guaranteed to be visible within the scope of second context?
var txOptions = new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted };
using (var transaction = new TransactionScope(TransactionScopeOption.Required, txOptions))
{
using (var context1 = new MyDbContext())
{
context1.Employees.Single(e => e.Id == 1).Salary += 1; // Update
context1.Employees.Remove(context1.Employees.Single(e => e.Id == 2)); // Delete
context1.Employees.Add(new Employee { Id = 3 }); // Add
context1.SaveChanges();
}
using (var context2 = new MyDbContext())
{
// are changes saved by context1 guaranteed to be visible here?
}
transaction.Complete();
}
Normally I would expect they are, but then I saw "No, this was a coincidence because the 2nd context reused the connection of the 1st from the connection pool. This is not guaranteed and will break under load." which made me puzzled. Could anyone please confirm or disprove this?