예제 #1
0
        protected static List <T> GetDTOListJSON <T>(ref SqlCommand command) where T : CommonBase
        {
            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);

                    while (reader.Read())
                    {
                        dtoList = parser.PopulateDTOList <T>(reader);
                    }
                    reader.Close();
                }
            }
            catch (SqlException oEx)
            {
                throw oEx;
            }
            finally
            {
                command.Connection.Close();
                command.Connection.Dispose();
            }
            return(dtoList);
        }
예제 #2
0
        // GetSingleDTO
        protected static T GetSingleDTO <T>(ref SqlCommand command) where T : CommonBase
        {
            T dto = null;

            try
            {
                SqlDataReader reader;
                DTOParser     parser = DTOParserFactory.GetParser(typeof(T));
                command.CommandTimeout = 3000; //tamaño time out  para enviar  en el config
                command.Connection.Open();
                reader = command.ExecuteReader();
                if (reader.Read())
                {
                    parser.PopulateOrdinals(reader);
                    dto = (T)parser.PopulateDTO(reader);
                    reader.Close();
                }
            }
            catch (SqlException oEx)
            {
                throw oEx;
            }
            finally
            {
                command.Connection.Close();
                command.Connection.Dispose();
            }

            // return the DTO, it's either populated with data or null.
            return(dto);
        }