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); }
public object GetObject(Type objectType, object objectKey, bool firstLevel) { if (objectKey == null) { return(null); } object entityObject = null; EntityKey entityKey = new EntityKey(objectType, objectKey); if (this.instances.Contains(entityKey)) { EntityMap map = this.Mappings[objectType]; if (map.AutoTrack) { Instance instance = (Instance)this.instances[entityKey]; entityObject = instance.EntityObject; } } if (entityObject == null) { Commands commands = this.Mappings.Commands(objectType); using (ObjectReader reader = this.GetObjectReader(commands.KeyQuery(objectType, objectKey), firstLevel)) { if (reader.Read()) { entityObject = reader.Current(); } } } return(entityObject); }
// Jeff Lanning ([email protected]): Added for OPath support. public object GetObject(CompiledQuery query, bool firstLevel, object[] parameters) { //NOTE: Longhorn 4074 throws an exception if more than one record is returned. // Decided it was better (and faster) not to do the same. using (ObjectReader reader = this.GetObjectReader(query, true, parameters)) { return((reader.Read()) ? reader.Current() : null); } }
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); }
private System.Collections.ObjectModel.Collection <T> GetCollection <T>(ObjectReader reader) { System.Collections.ObjectModel.Collection <T> collection = new System.Collections.ObjectModel.Collection <T>(); try { while (reader.Read()) { collection.Add((T)reader.Current()); } } finally { if (reader != null) { reader.Close(); } } return(collection); }