public async Task InvokeAsync <TResult>(ExecutionContext executionContext) { try { switch (executionContext.Type) { case ExecutionType.Execute: { var recordsAffected = await _commandExecuter.ExecuteNonQueryAsync(executionContext); executionContext.Result.SetData(recordsAffected); return; } case ExecutionType.ExecuteScalar: { await ParseExecuteScalarDbValueAsync <TResult>(executionContext); return; } case ExecutionType.GetDataSet: { var resultData = await _commandExecuter.GetDateSetAsync(executionContext); executionContext.Result.SetData(resultData); return; } case ExecutionType.GetDataTable: { var resultData = await _commandExecuter.GetDateTableAsync(executionContext); executionContext.Result.SetData(resultData); return; } case ExecutionType.Query: case ExecutionType.QuerySingle: { executionContext.DataReaderWrapper = await _commandExecuter.ExecuteReaderAsync(executionContext); break; } default: throw new ArgumentOutOfRangeException(); } Next.Invoke <TResult>(executionContext); } finally { if (executionContext.DataReaderWrapper != null) { executionContext.DataReaderWrapper.Close(); executionContext.DataReaderWrapper.Dispose(); } } }