public void Invoke <TResult>(ExecutionContext executionContext) { try { switch (executionContext.Type) { case ExecutionType.Execute: { var recordsAffected = _commandExecuter.ExecuteNonQuery(executionContext); executionContext.Result.SetData(recordsAffected); return; } case ExecutionType.ExecuteScalar: { ParseExecuteScalarDbValue <TResult>(executionContext); return; } case ExecutionType.GetDataSet: { var resultData = _commandExecuter.GetDateSet(executionContext); executionContext.Result.SetData(resultData); return; } case ExecutionType.GetDataTable: { var resultData = _commandExecuter.GetDateTable(executionContext); executionContext.Result.SetData(resultData); return; } case ExecutionType.Query: case ExecutionType.QuerySingle: { executionContext.DataReaderWrapper = _commandExecuter.ExecuteReader(executionContext); break; } default: throw new ArgumentOutOfRangeException(); } Next.Invoke <TResult>(executionContext); } finally { if (executionContext.DataReaderWrapper != null) { executionContext.DataReaderWrapper.Close(); executionContext.DataReaderWrapper.Dispose(); } } }