/// <summary> /// Save all Changes -- Insert, Update, or Delete /// </summary> /// <param name="entityObjects" type="System.Collections.ICollection"> /// Collection of object instances to perform action on /// </param> /// <param name="persistDepth" type="Wilson.ORMapper.PersistDepth"> /// The depth at which to persist child objects /// </param> public void PersistChanges(ICollection entityObjects, PersistDepth persistDepth) { foreach (object entityObject in entityObjects) { Internals.Instance instance = this.context[entityObject]; // Jeff Lanning ([email protected]): Added null check for better error message. if (instance == null) { throw new ORMapperException("Entity object '" + entityObject.GetType().ToString() + "' is not being tracked."); } instances.Add(new PersistOptions(instance, persistDepth)); instance.PersistChanges(this, persistDepth); } }
/// <summary>Advances the ObjectReader to the next record.</summary> /// <returns>True if there are more objects; otherwise, false.</returns> public bool Read() { bool read; if (this.firstRead) { this.firstRead = false; read = this.hasObjects; } else { read = this.data.Read(); } if (read) { if (this.firstLevel) { Internals.LocalStore.Reset(this.objectType); } Internals.EntityMap entity = this.context.Mappings[this.ObjectType]; Type instanceType = this.ObjectType; if (entity.SubTypes.Count > 0) { string typeValue = this.data[entity.TypeField].ToString(); if (entity.SubTypes.ContainsKey(typeValue)) { instanceType = Internals.EntityMap.GetType((string)entity.SubTypes[typeValue]); } } this.current = Activator.CreateInstance(instanceType, true); Internals.Instance instance = new Internals.Instance(this.context, this.current, this.data); if (this.hasEvents) { ((IObjectNotification)this.current).OnMaterialized(this.data); } if (this.context.Mappings[objectType.ToString()].AutoTrack) { this.context.StartTracking(instance); } } else { this.current = null; this.Close(); } return(read); }