Example #1
0
        /// <summary>
        /// Adds a table adapter to the shared transaction.
        /// </summary>
        /// <remarks>
        /// This effectively opens a database transaction if this is the first table adapter
        /// in the list of this shared transaction group
        /// </remarks>
        /// <param name="adapter"></param>
        public void BeginTransaction(ISqlDataAdapterExtension adapter)
        {
            if (this.adapters.Contains(adapter))
            {
                throw new ArgumentException("adapter is already sharing this transaction.");
            }

            if (this.transaction == null)
            {
                this.transaction = this.Connection.BeginTransaction(this.TransactionName);
            }

            this.adapters.Add(adapter);
            adapter.SqlTransaction = this.transaction;
        }
Example #2
0
 /// <summary>
 /// Returns the database transaction assigned to a table adapter
 /// </summary>
 /// <param name="adapter"></param>
 /// <returns></returns>
 public static SqlTransaction GetSqlTransaction(ISqlDataAdapterExtension adapter)
 {
     if (adapter.SqlDataAdapter.UpdateCommand != null && adapter.SqlDataAdapter.UpdateCommand.Transaction != null)
     {
         return(adapter.SqlDataAdapter.UpdateCommand.Transaction);
     }
     else if (adapter.SqlDataAdapter.InsertCommand != null && adapter.SqlDataAdapter.InsertCommand.Transaction != null)
     {
         return(adapter.SqlDataAdapter.InsertCommand.Transaction);
     }
     else if (adapter.SqlDataAdapter.DeleteCommand != null && adapter.SqlDataAdapter.DeleteCommand.Transaction != null)
     {
         return(adapter.SqlDataAdapter.DeleteCommand.Transaction);
     }
     else
     {
         return(null);
     }
 }
Example #3
0
 /// <summary>
 /// Sets a database transaction on a table adapter
 /// </summary>
 /// <param name="adapter"></param>
 /// <param name="transaction"></param>
 public static void SetSqlTransaction(ISqlDataAdapterExtension adapter, SqlTransaction transaction)
 {
     if (adapter.SqlDataAdapter.UpdateCommand != null)
     {
         adapter.SqlDataAdapter.UpdateCommand.Transaction = transaction;
         adapter.SqlDataAdapter.UpdateCommand.Connection  = transaction.Connection;
     }
     if (adapter.SqlDataAdapter.InsertCommand != null)
     {
         adapter.SqlDataAdapter.InsertCommand.Transaction = transaction;
         adapter.SqlDataAdapter.InsertCommand.Connection  = transaction.Connection;
     }
     if (adapter.SqlDataAdapter.DeleteCommand != null)
     {
         adapter.SqlDataAdapter.DeleteCommand.Transaction = transaction;
         adapter.SqlDataAdapter.DeleteCommand.Connection  = transaction.Connection;
     }
     if (adapter.SqlDataAdapter.SelectCommand != null)
     {
         adapter.SqlDataAdapter.SelectCommand.Transaction = transaction;
         adapter.SqlDataAdapter.SelectCommand.Connection  = transaction.Connection;
     }
 }
Example #4
0
 /// <summary>
 /// Returns the <c>SelectCommand</c> of a table adapter (which surprisingly is missing on the TableAdapter's interface)
 /// </summary>
 /// <param name="adapter"></param>
 /// <returns></returns>
 public static SqlCommand GetSelectCommand(ISqlDataAdapterExtension adapter)
 {
     // Note: we never need to check whether CommanCollection is initialized as
     // this is done automatically upon the first call to this property!
     return(adapter.CommandCollection[0]);
 }