예제 #1
0
        // GetSingleDTO
        protected static T GetSingleDto <T>(ref OracleCommand command) where T : DtoBase
        {
            T dto = null;

            try
            {
                command.Connection.Open();
                OracleDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    reader.Read();
                    DtoParserSqlOracle 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);
        }
예제 #2
0
        // GetDTOList
        protected static List <T> GetDtoList <T>(ref OracleCommand command) where T : DtoBase
        {
            List <T> dtoList = new List <T>();

            try
            {
                command.Connection.Open();
                OracleDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    // Get a parser for this DTO type and populate
                    // the ordinals.
                    DtoParserSqlOracle 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);
        }