src/Projac.Sql/Executors/TransactionalSqlCommandExecutor.cs
/// <summary>
///     Executes the specified commands asynchronously.
/// </summary>
/// <param name="commands">The commands.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
///     A <see cref="Task" /> that will return the number of <see cref="SqlNonQueryCommand">commands</see>
///     executed.
/// </returns>
/// <exception cref="System.ArgumentNullException">Thrown when <paramref name="commands" /> are <c>null</c>.</exception>
Executes the specified commands asynchronously.
Executes the specified commands asynchronously .
public async Task<int> ExecuteNonQueryAsync(IEnumerable<SqlNonQueryCommand> commands, CancellationToken cancellationToken)
        {
            if (commands == null) 
                throw new ArgumentNullException("commands");
            using (var dbConnection = _dbProviderFactory.CreateConnection())
            {
                dbConnection.ConnectionString = _connectionString;
                await dbConnection.OpenAsync(cancellationToken);
                try
                {
                    var count = 0;
                    using (var dbTransaction = dbConnection.BeginTransaction(_isolationLevel))
                    {
                        using (var dbCommand = dbConnection.CreateCommand())
                        {
                            dbCommand.Connection = dbConnection;
                            dbCommand.Transaction = dbTransaction;
                            dbCommand.CommandTimeout = _commandTimeout;
                            foreach (var command in commands)
                            {
                                dbCommand.CommandType = command.Type;
                                dbCommand.CommandText = command.Text;
                                dbCommand.Parameters.Clear();
                                dbCommand.Parameters.AddRange(command.Parameters);
                                await dbCommand.ExecuteNonQueryAsync(cancellationToken);
                                count++;
                            }
                        }
                        dbTransaction.Commit();
                    }
                    return count;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
        }
public async Task < int > ExecuteNonQueryAsync ( IEnumerable < SqlNonQueryCommand > commands , CancellationToken cancellationToken ) { if ( commands == null ) throw new ArgumentNullException ( " " ) ; using ( var dbConnection = _dbProviderFactory . CreateConnection ( ) ) { dbConnection . ConnectionString = _connectionString ; await dbConnection . OpenAsync ( cancellationToken ) ; try { var count = 0 ; using ( var dbTransaction = dbConnection . BeginTransaction ( _isolationLevel ) ) { using ( var dbCommand = dbConnection . CreateCommand ( ) ) { dbCommand . Connection = dbConnection ; dbCommand . Transaction = dbTransaction ; dbCommand . CommandTimeout = _commandTimeout ; foreach ( var command in commands ) { dbCommand . CommandType = command . Type ; dbCommand . CommandText = command . Text ; dbCommand . Parameters . Clear ( ) ; dbCommand . Parameters . AddRange ( command . Parameters ) ; await dbCommand . ExecuteNonQueryAsync ( cancellationToken ) ; count ++ ; } } dbTransaction . Commit ( ) ; } return count ; } finally { dbConnection . Close ( ) ; } } }
Executes the specified commands asynchronously.
Executes the specified commands asynchronously .
A  that will return the number of commands
A that will return the number of commands
Thrown when  are null
Thrown when are null
commands
IEnumerable<SqlNonQueryCommand>
None
cancellationToken
CancellationToken
The cancellation token.
The cancellation token .