Tiraggo.Interfaces.tgTransactionScope.Enlist C# (CSharp) Method

Enlist() public static method

You should never call this directly, the providers call this method.
public static Enlist ( IDbCommand cmd, string connectionString, CreateIDbConnectionDelegate creator ) : void
cmd IDbCommand The command to enlist into a transaction
connectionString string The connection string passed to the CreateIDbConnectionDelegate delegate
creator CreateIDbConnectionDelegate The delegate previously registered by the provider
return void
        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;
            }
        }