public static void Enlist(IDbCommand cmd, string connectionString, CreateIDbConnectionDelegate creator)
{
tgTransactionScope currentTx = GetCurrentTx();
if (currentTx == null || currentTx.option == tgTransactionScopeOption.Suppress)
{
cmd.Connection = creator();
cmd.Connection.ConnectionString = connectionString;
cmd.Connection.Open();
}
else
{
Transaction tx = null;
if (currentTx.root.transactions.ContainsKey(connectionString))
{
tx = currentTx.root.transactions[connectionString] as Transaction;
}
else
{
tx = new Transaction();
IDbConnection cn = creator();
cn.ConnectionString = connectionString;
cn.Open();
// The .NET framework has a bug in that the IDbTransaction only maintains
// a weak reference to the Connection, thus, we put a strong reference
// on it.
tx.sqlCn = cn;
if (_isolationLevel != IsolationLevel.Unspecified)
{
tx.sqlTx = cn.BeginTransaction(_isolationLevel);
}
else
{
tx.sqlTx = cn.BeginTransaction();
}
currentTx.root.transactions[connectionString] = tx;
}
cmd.Connection = tx.sqlTx.Connection;
cmd.Transaction = tx.sqlTx;
}
}