protected static T GetSingle <T>(ref DbCommand command) where T : DTOBase { try { command.Connection.Open(); var reader = command.ExecuteReader(); try { if (reader.HasRows && reader.Read()) { var parser = DTOParserFactory.GetParserOf <T>(reader); return((T)parser.PopulateDTO(reader)); } } finally { if (reader != null) { reader.Close(); ((IDisposable)reader).Dispose(); } } } finally { if (command != null && command.Connection != null) { command.Connection.Close(); ((IDisposable)command.Connection).Dispose(); } } return(null); }
protected static List <T> GetDTOList <T>(ref DbCommand command) where T : DTOBase { List <T> dtoList = null; try { command.Connection.Open(); var reader = command.ExecuteReader(); try { if (reader.HasRows) { var parser = DTOParserFactory.GetParserOf <T>(reader); dtoList = new List <T>(); while (reader.Read()) { T dto = null; dto = (T)parser.PopulateDTO(reader); dtoList.Add(dto); } } } finally { if (reader != null) { reader.Close(); ((IDisposable)reader).Dispose(); } } } finally { if (command != null && command.Connection != null) { command.Connection.Close(); ((IDisposable)command.Connection).Dispose(); } } return(dtoList); }