/// <summary> /// Executes a DbDataReader asynchronously and returns a list of mapped column values to the properties of /// </summary> /// <param name="command"></param> /// <param name="handleResults"></param> /// <param name="commandBehaviour"></param> /// <param name="ct"></param> /// <returns></returns> public static async Task ExecuteStoredProcedureAsync(this DbCommand command, Action <StoredProcedureResults> handleResults, CommandBehavior commandBehaviour = CommandBehavior.Default, CancellationToken ct = default(CancellationToken)) { if (handleResults == null) { throw new ArgumentNullException(nameof(handleResults)); } using (command) { if (command.Connection.State == ConnectionState.Closed) { await command.Connection.OpenAsync(ct).ConfigureAwait(false); } try { using (var reader = await command.ExecuteReaderAsync(commandBehaviour, ct).ConfigureAwait(false)) { var spResults = new StoredProcedureResults(reader); handleResults(spResults); } } finally { command.Connection.Close(); } } }
/// <summary> /// Executes a DbDataReader and returns a list of mapped column values to the properties /// </summary> /// <param name="command"></param> /// <param name="handleResults"></param> /// <param name="commandBehaviour"></param> /// <returns></returns> public static void ExecuteStoredProcedure(this DbCommand command, Action <StoredProcedureResults> handleResults, CommandBehavior commandBehaviour = CommandBehavior.Default) { if (handleResults == null) { throw new ArgumentNullException(nameof(handleResults)); } using (command) { if (command.Connection.State == ConnectionState.Closed) { command.Connection.Open(); } try { using (var reader = command.ExecuteReader(commandBehaviour)) { var sprocResults = new StoredProcedureResults(reader); handleResults(sprocResults); } } finally { command.Connection.Close(); } } }