private IEnumerable <T> _fastPipeline() { var connectionName = Model.ConnectionName(_t); using (var cmd = Destrier.Execute.Command(connectionName)) { cmd.CommandText = this.QueryBody; cmd.CommandType = System.Data.CommandType.Text; Destrier.Execute.Utility.AddParametersToCommand(_parameters, cmd, connectionName); using (var dr = new IndexedSqlDataReader(cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection), type: _t)) { while (dr.Read()) { T newObject = (T)ReflectionHelper.GetNewObject(_t); dr.DeepPopulate(newObject, _t); yield return(newObject); } } } }
private IEnumerable <T> _slowPipeline() { var list = new List <T>(); var connectionName = Model.ConnectionName(_t); using (var cmd = Destrier.Execute.Command(connectionName)) { cmd.CommandText = this.QueryBody; cmd.CommandType = System.Data.CommandType.Text; Destrier.Execute.Utility.AddParametersToCommand(_parameters, cmd, connectionName); using (var dr = new IndexedSqlDataReader(cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection), type: _t)) { var objectLookups = new Dictionary <Type, Dictionary <Object, Object> >(); var parentDict = new Dictionary <Object, Object>(); objectLookups.Add(_t, parentDict); while (dr.Read()) { var newObject = (T)ReflectionHelper.GetNewObject(_t); dr.DeepPopulate(newObject, objectLookups: objectLookups, thisType: _t); list.Add(newObject); } if (_builder.ChildCollections.Any()) { foreach (var cm in _builder.ChildCollections.Where(cm => !cm.IsLazy)) { var root = cm.Root; var parent = cm.Parent ?? cm.Root; var referencedParentPrimaryKey = cm.ReferencedProperty; dr.NextResult(cm.CollectionType); if (!objectLookups.ContainsKey(cm.CollectionType)) { objectLookups.Add(cm.CollectionType, new Dictionary <Object, Object>()); } dr.ReadIntoParentCollection(cm.CollectionType, (reader, obj) => { var pkValue = referencedParentPrimaryKey.GetValue(obj); var pkValueAsString = pkValue != null ? pkValue.ToString() : null; var objPrimaryKeys = Model.ColumnsPrimaryKey(cm.CollectionType); object objPrimaryKeyValue = Model.InstancePrimaryKeyValue(cm.CollectionType, obj); object parentObj = null; objectLookups[cm.DeclaringType].TryGetValue(pkValueAsString, out parentObj); if (parentObj != null) { var parentCollectionProperty = cm.Property; //new up the collection if it hasn't been delcared yet. if (parentCollectionProperty.GetValue(parentObj) == null) { parentCollectionProperty.SetValue(parentObj, ReflectionHelper.GetNewObject(cm.Type)); } //set up lookup for the object Dictionary <Object, Object> objLookup = null; objectLookups.TryGetValue(cm.CollectionType, out objLookup); if (objLookup != null && objPrimaryKeyValue != null) { if (!objLookup.ContainsKey(objPrimaryKeyValue)) { objLookup.Add(objPrimaryKeyValue, obj); } else { obj = objLookup[objPrimaryKeyValue]; } } var collection = parentCollectionProperty.GetValue(parentObj); ((System.Collections.IList)collection).Add(obj); } }, populateFullResults: true, advanceToNextResultAfter: false, objectLookups: objectLookups); } } } } return(list); }