@Walaa - This doesn't look like my code as there is no TransasctionScope.
@daelmo:
Thanks, that certainly makes it easier to test
I've modified it some more to make sure that the lock is taken by outsider before the insert can run:
static ManualResetEvent lockTaken = new ManualResetEvent(false);
static void Main(string[] args)
{
Thread outsider = new Thread(new ThreadStart(new Outsider().Run));
outsider.Start();
lockTaken.WaitOne();
Console.WriteLine("ts starting.");
using (var ts = new TransactionScope())
{
var t = new TEntity { B = 1 };
var daa = new DataAccessAdapterRecovery(@"Server=localhost;Database=lltest;Trusted_Connection=True;");
daa.CommandTimeOut = 5;
daa.SaveEntity(t);
ts.Complete();
}
Console.WriteLine("ts complete.");
outsider.Join();
Console.WriteLine("done.");
Console.ReadLine();
}
public class Outsider
{
public void Run()
{
var adapter = new DataAccessAdapter(@"Server=localhost;Database=lltest;Trusted_Connection=True;");
adapter.StartTransaction(System.Data.IsolationLevel.Serializable, "outsider");
var results = new EntityCollection<TEntity>();
adapter.FetchEntityCollection(results, null);
Console.WriteLine("outsider lock taken.");
lockTaken.Set();
Thread.Sleep(7000);
adapter.Commit();
Console.WriteLine("outsider commit.");
}
}
I don't believe it is that time sensitive: I tried with sleeps of 5500, 6000, and 7000 and all throw the TransactionAbortedException.
Will try with EntityFramework to see what the behaviour is.