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