src/Projac.Sql/Executors/SqlCommandExecutor.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 a <see cref="object">scalar value</see>.
/// </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<object> ExecuteScalarAsync(SqlQueryCommand 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 dbCommand = dbConnection.CreateCommand())
                    {
                        dbCommand.Connection = dbConnection;
                        dbCommand.CommandTimeout = _commandTimeout;
                        dbCommand.CommandType = command.Type;
                        dbCommand.CommandText = command.Text;
                        dbCommand.Parameters.Clear();
                        dbCommand.Parameters.AddRange(command.Parameters);
                        return dbCommand.ExecuteScalarAsync(cancellationToken);
                    }
                }
                finally
                {
                    dbConnection.Close();
                }
            }
        }
public async Task < object > ExecuteScalarAsync ( SqlQueryCommand command , CancellationToken cancellationToken ) { if ( command == null ) throw new ArgumentNullException ( " " ) ; using ( var dbConnection = _dbProviderFactory . CreateConnection ( ) ) { dbConnection . ConnectionString = _connectionString ; await dbConnection . OpenAsync ( cancellationToken ) ; try { using ( var dbCommand = dbConnection . CreateCommand ( ) ) { dbCommand . Connection = dbConnection ; dbCommand . CommandTimeout = _commandTimeout ; dbCommand . CommandType = command . Type ; dbCommand . CommandText = command . Text ; dbCommand . Parameters . Clear ( ) ; dbCommand . Parameters . AddRange ( command . Parameters ) ; return dbCommand . ExecuteScalarAsync ( cancellationToken ) ; } } finally { dbConnection . Close ( ) ; } } }
Executes the specified command asynchronously.
Executes the specified command asynchronously .
A  that will return a scalar value
A that will return a scalar value
Thrown when  is null
Thrown when is null
command
SqlQueryCommand
None
cancellationToken
CancellationToken
The cancellation token.
The cancellation token .