예제 #1
0
        private ObjectSet <T> GetObjectSet <T>(ObjectReader reader)
        {
            ObjectSet <T> objectSet = null;

            try {
                objectSet = new ObjectSet <T>(reader.PageIndex, reader.PageCount, reader.TotalCount);
                while (reader.Read())
                {
                    T      entityObject = (T)reader.Current();
                    object keyValue     = reader.ObjectKey();
                    objectSet.Add(keyValue, entityObject);
                }
            }
            catch (ORMapperException) {
                throw;
            }
            catch (Exception exception) {
                throw new ORMapperException("GetObjectSet<T> failed for " + reader.ObjectType.ToString(), exception);
            }
            finally {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(objectSet);
        }
예제 #2
0
        private IList GetCollection(Type collectionType, ObjectReader reader)
        {
            IList collection = null;

            if (collectionType == typeof(ObjectSet))
            {
                collection = new ObjectSet(reader.ObjectType, reader.PageIndex, reader.PageCount, reader.TotalCount);
            }
            else if (collectionType == typeof(ObjectList))
            {
                ObjectSet objectSet = new ObjectSet(reader.ObjectType, reader.PageIndex, reader.PageCount, reader.TotalCount);
                collection = new ObjectList(this, objectSet);
            }
            else
            {
                collection = (IList)Activator.CreateInstance(collectionType, true);
            }

            try {
                while (reader.Read())
                {
                    if (collectionType == typeof(IObjectSet))
                    {
                        ((IObjectSet)collection).Add(reader.ObjectKey(), reader.Current());
                    }
                    else
                    {
                        collection.Add(reader.Current());
                    }
                }
            }
            finally {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(collection);
        }