public static IList <T> ExecuteStpAndGetList <T>(this DbCommand command, CommandBehavior commandBehaviour = CommandBehavior.Default) { using (command) { if (command.Connection.State == ConnectionState.Closed) { command.Connection.Open(); } try { using (var reader = command.ExecuteReader(commandBehaviour)) { var sprocResults = new SprocResults(reader); return(sprocResults.ReadToList <T>()); } } finally { command.Connection.Close(); } } }
public static async Task <IEnumerable <T> > ExecuteStpAsync <T>(this DbCommand command, CommandBehavior commandBehaviour = CommandBehavior.Default) { using (command) { if (command.Connection.State == ConnectionState.Closed) { command.Connection.Open(); } try { using (var reader = await command.ExecuteReaderAsync(commandBehaviour)) { var sprocResults = new SprocResults(reader); return(sprocResults.ReadToList <T>()); } } finally { command.Connection.Close(); } } }