Beispiel #1
0
        public static async Task <object> ExecuteScalarAsync(this IDbCommandAsyncExecutor executor, ExecuteNonReaderRequest request)
        {
            object scalar = null;
            await executor.ExecuteAsync(
                request,
                async command => scalar = await command.ExecuteScalarAsync(request.CancellationToken));

            return(scalar);
        }
Beispiel #2
0
        public static Task ExecuteAsync(this IDbCommandAsyncExecutor executor, ExecuteNonReaderRequest request, Func <DbCommand, Task> execute)
        {
            var requests = new[]
            {
                new ExecuteCommandAsyncRequest(request.CreateCommandRequest, execute)
            };

            return(executor.ExecuteAsync(requests, request.CancellationToken));
        }
Beispiel #3
0
        public static async Task <int> ExecuteNonQueryAsync(this IDbCommandAsyncExecutor executor, ExecuteNonReaderRequest request)
        {
            var affectedRows = 0;
            await executor.ExecuteAsync(
                request,
                async command => affectedRows = await command.ExecuteNonQueryAsync(request.CancellationToken));

            return(affectedRows);
        }
Beispiel #4
0
 public static Task ExecuteReaderAsync(this IDbCommandAsyncExecutor executor, ExecuteReaderRequest request, Func <DbDataReader, Task> readResults)
 {
     return(executor.ExecuteAsync(
                new ExecuteNonReaderRequest(request.CreateCommandRequest, request.CancellationToken),
                async command =>
     {
         using (var dataReader = await command.ExecuteReaderAsync(request.CommandBehavior, request.CancellationToken))
             await readResults(dataReader);
     }));
 }
Beispiel #5
0
 private static Task ExecuteAsync(this IDbCommandAsyncExecutor executor, IEnumerable <ExecuteCommandAsyncRequest> requests, CancellationToken cancellationToken)
 {
     return(executor.ExecuteAsync(async connection =>
     {
         foreach (var request in requests)
         {
             using (var command = connection.CreateCommand(request.CreateCommandRequest))
                 await request.Execute(command);
         }
     }, cancellationToken));
 }