Hello --
Basics:
LLBLGen: 2.0.0.0, Dec. 6, 2006
Database: SQL Server 2005, SP2 (snapshot isolation is enabled)
Runtime: SqlServer DQE: v2.0.50727; ORMSupportClasses - v2.0.50727
.Net 2.0; C#
Adapter
I'm a little unclear on how the adapter.TransactionIsolationLevel property functions. Essentially, what I want to do is specify what isolation level SELECTs run under to avoid locks and concurrency issues.
In basic tests that I've done, setting adapter.TransactionIsolationLevel doesn't have an effect unless a new transaction is created. Is that by design? I'd prefer not to have to create a transaction explicitly and instead just have the "connection" or request run under the specified isolation level.
Here's some sample code:
This example throws a time out exception due, which I would expect if the Isolation level was Read Committed:
[NUnit.Framework.Test()]
public void TestIsolationLevels_UseSnapshot()
{
DataAccessAdapter adapterWriter;
DataAccessAdapter adapterReader;
CountryEntity USandA = new CountryEntity(215);
CountryEntity USandA2 = new CountryEntity();
CountryEntity boratHome = new CountryEntity();
boratHome.CountryAbr2 = "KZ";
USandA2.CountryAbr2 = "US";
using (adapterWriter = new DataAccessAdapter())
{
adapterWriter.TransactionIsolationLevel = System.Data.IsolationLevel.ReadCommitted;
Assert.IsTrue(adapterWriter.FetchEntity(USandA));
USandA.CountryName = "USATemp";
adapterWriter.StartTransaction(System.Data.IsolationLevel.ReadCommitted, "update");
Assert.IsTrue(adapterWriter.SaveEntity(USandA), "failed to save usa country");
using (adapterReader = new DataAccessAdapter())
{
adapterReader.TransactionIsolationLevel = System.Data.IsolationLevel.Snapshot;
// now get original country
adapterReader.FetchEntityUsingUniqueConstraint(USandA2, USandA2.ConstructFilterForUCCountryAbr2());
Assert.AreEqual("United States", USandA2.CountryName);
}
adapterWriter.Rollback();
}
}
This code example functions properly, as I explicitly open a transaction and specify the isolation level:
[NUnit.Framework.Test()]
public void TestIsolationLevels_UseExplicitTransaction()
{
DataAccessAdapter adapterWriter;
DataAccessAdapter adapterReader;
CountryEntity USandA = new CountryEntity(215);
CountryEntity USandA2 = new CountryEntity();
USandA2.CountryAbr2 = "US";
using (adapterWriter = new DataAccessAdapter())
{
adapterWriter.TransactionIsolationLevel = System.Data.IsolationLevel.ReadCommitted;
Assert.IsTrue(adapterWriter.FetchEntity(USandA));
USandA.CountryName = "USATemp";
adapterWriter.StartTransaction(System.Data.IsolationLevel.ReadCommitted, "update");
Assert.IsTrue(adapterWriter.SaveEntity(USandA), "failed to save usa country");
using (adapterReader = new DataAccessAdapter())
{
adapterReader.StartTransaction(System.Data.IsolationLevel.Snapshot, "reader");
// now get original country
adapterReader.FetchEntityUsingUniqueConstraint(USandA2, USandA2.ConstructFilterForUCCountryAbr2());
Assert.AreEqual("United States", USandA2.CountryName);
}
adapterWriter.Rollback();
}
}
I know that I'm running an older build, and if you think it is a bug, I'd be happy to try with the latest version.
Thanks.