protected virtual CompositeCommand Compose(string title, params CommandBase <CommandContext>[] commands) { var args = new CommandCreatedEventArgs { Command = new CompositeCommand(title, commands.Where(c => c != null).ToArray()) }; if (CreatedCommand != null) { CreatedCommand.Invoke(this, args); } return(args.Command); }
public async CreateCommandTask CreateCommandAsync(string sql, object parameters = null, DbConnection dbConnection = null, DbTransaction dbTransaction = null, int commandTimeout = UseDefaultCommandTimeout, CommandType commandType = CommandType.Text) { if (dbTransaction != null && dbConnection != null && dbTransaction.Connection != dbConnection) { throw new InvalidOperationException("The specified DbTransaction does not belong to the specified DbConnection."); } if (commandTimeout == UseDefaultCommandTimeout) { commandTimeout = DefaultCommandTimeout; } DbConnection iDbConnection = null; try { var dbCommand = (dbConnection ?? dbTransaction?.Connection ?? (iDbConnection = await OpenConnectionAsync())).CreateCommand(); dbCommand.CommandText = sql; dbCommand.CommandTimeout = commandTimeout; dbCommand.CommandType = commandType; dbCommand.Transaction = dbTransaction; if (parameters != null) { dbCommand.SetParameters(parameters); } CreatedCommand?.Invoke(this, dbCommand); return(dbCommand); } catch { iDbConnection?.Dispose(); throw; } }