protected static List <T> GetDTOList <T>(ref SqlCommand sqlCmd) where T : DTOBase { List <T> dtoList = new List <T>(); try { sqlCmd.Connection.Open(); SqlDataReader sqlReader = sqlCmd.ExecuteReader(); if (sqlReader.HasRows) { DTOParser baseParser = DTOParserFactory.GetParser(typeof(T)); baseParser.PopulateOrdinals(sqlReader); while (sqlReader.Read()) { T currentDTO = null; currentDTO = (T)baseParser.PopulateDTO(sqlReader); dtoList.Add(currentDTO); } sqlReader.Close(); } } catch (Exception e) { throw e; } finally { sqlCmd.Connection.Close(); sqlCmd.Connection.Dispose(); } return(dtoList); }
protected static T GetDTO <T>(ref SqlCommand sqlCmd) where T : DTOBase { T currentDTO = null; try { sqlCmd.Connection.Open(); SqlDataReader sqlReader = sqlCmd.ExecuteReader(); if (sqlReader.HasRows) { sqlReader.Read(); DTOParser baseParser = DTOParserFactory.GetParser(typeof(T)); baseParser.PopulateOrdinals(sqlReader); currentDTO = (T)baseParser.PopulateDTO(sqlReader); sqlReader.Close(); } else { return(null); } } catch (Exception e) { throw e; } finally { sqlCmd.Connection.Close(); sqlCmd.Connection.Dispose(); } return(currentDTO); }
// GetSingleDTO protected static T GetSingleDTO <T>(ref SqlCommand command) where T : DTOBase { T dto = null; try { command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { reader.Read(); DTOParser parser = DTOParserFactory.GetParser(typeof(T)); parser.PopulateOrdinals(reader); dto = (T)parser.PopulateDTO(reader); reader.Close(); } else { // S'il n'y a pas de données, nous renvoyons null. dto = null; } } catch (Exception e) { throw new Exception("Error populating data", e); } finally { command.Connection.Close(); command.Connection.Dispose(); } // Renvoie le DTO, rempli soit avec des données soit avec null. return(dto); }
// GetSingleDTO protected static T GetSingleDTO <T>(ref SqlCommand command) where T : DTOBase { T dto = null; try { command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { reader.Read(); DTOParser parser = DTOParserFactory.GetParser(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 SqlCommand command) where T : DTOBase { List <T> dtoList = new List <T>(); try { command.Connection.Open(); command.CommandTimeout = 3600; SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { // Obtenir un analyseur (parser) pour ce type de DTO et remplir les ordinaux. DTOParser parser = DTOParserFactory.GetParser(typeof(T)); parser.PopulateOrdinals(reader); // Utilise l'analyseur (parser) pour construire notre liste de DTO. while (reader.Read()) { T dto = null; dto = (T)parser.PopulateDTO(reader); dtoList.Add(dto); } reader.Close(); } else { // S'il n'y a pas de données, nous renvoyons null. dtoList = null; } } catch (Exception e) { throw new Exception("Error populating data", e); } finally { command.Connection.Close(); command.Connection.Dispose(); } return(dtoList); }
// GetDTOList protected static List <T> GetDTOList <T>(ref SqlCommand command) where T : DTOBase { List <T> dtoList = new List <T>(); try { command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { // Get a parser for this DTO type and populate // the ordinals. DTOParser parser = DTOParserFactory.GetParser(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); }