protected static List <T> GetDtoList <T>(ref SqlCommand command) where T : DtoBase { var dtoList = new List <T>(); try { command.Connection.Open(); var reader = command.ExecuteReader(); if (reader.HasRows) { var parser = DtoParserFactory.GetParser(typeof(T)); parser.PopulateOrdinals(reader); while (reader.Read()) { var dto = (T)parser.PopulateDto(reader); dtoList.Add(dto); } reader.Close(); } else { dtoList = null; } } catch (Exception e) { throw new Exception("Error populating data", e); } finally { command.Connection.Close(); command.Connection.Dispose(); } return(dtoList); }
// GetSingleDTO protected static T GetSingleDto <T>(ref OracleCommand command) where T : DtoBase { T dto = null; try { command.Connection.Open(); var reader = command.ExecuteReader(); if (reader.HasRows) { reader.Read(); var parser = DtoParserFactory.GetParserOracleClient(typeof(T)); parser.PopulateOrdinals(reader); dto = (T)parser.PopulateDto(reader); reader.Close(); } else { // Whever there's no data, we return null. dto = null; } } catch (Exception e) { throw new Exception("Error populating data", e); } finally { command.Connection.Close(); command.Connection.Dispose(); } // return the DTO, it's either populated with data or null. return(dto); }
// GetDTOList protected static List <T> GetDtoList <T>(ref OracleCommand command) where T : DtoBase { var dtoList = new List <T>(); try { command.Connection.Open(); var reader = command.ExecuteReader(); if (reader.HasRows) { // Get a parser for this DTO type and populate // the ordinals. var parser = DtoParserFactory.GetParserOracleClient(typeof(T)); parser.PopulateOrdinals(reader); // Use the parser to build our list of DTOs. while (reader.Read()) { T dto = null; dto = (T)parser.PopulateDto(reader); dtoList.Add(dto); } reader.Close(); } else { // Whenver there's no data, we return null. //dtoList = null; } } catch (Exception e) { throw new Exception("Error populating data", e); } finally { command.Connection.Close(); command.Connection.Dispose(); } return(dtoList); }