private void ObserveUntrackedObjects(MetaType type, object item, Dictionary <object, object> visited) { if (!visited.ContainsKey(item)) { visited.Add(item, item); TrackedObject trackedObject = this.tracker.GetTrackedObject(item); if (trackedObject == null) { trackedObject = this.tracker.Track(item); trackedObject.ConvertToNew(); } else if (trackedObject.IsDead || trackedObject.IsRemoved) { return; } foreach (RelatedItem item2 in this.services.GetParents(type, item)) { this.ObserveUntrackedObjects(item2.Type, item2.Item, visited); } if (trackedObject.IsNew && !trackedObject.IsPendingGeneration(trackedObject.Type.IdentityMembers)) { trackedObject.SynchDependentData(); } foreach (RelatedItem item3 in this.services.GetChildren(type, item)) { this.ObserveUntrackedObjects(item3.Type, item3.Item, visited); } } }
/// <summary> /// Adds an entity in a pending insert state to this ALinq.Table<TEntity>. /// </summary> /// <param name="entity">The entity to be added.</param> public void InsertOnSubmit(TEntity entity) { if (entity == null) { throw Error.ArgumentNull("entity"); } CheckReadOnly(); context.CheckNotInSubmitChanges(); context.VerifyTrackingEnabled(); MetaType inheritanceType = metaTable.RowType.GetInheritanceType(entity.GetType()); if (!IsTrackableType(inheritanceType)) { throw Error.TypeCouldNotBeAdded(inheritanceType.Type); } TrackedObject trackedObject = context.Services.ChangeTracker.GetTrackedObject(entity); if (trackedObject == null) { context.Services.ChangeTracker.Track(entity).ConvertToNew(); } else if (trackedObject.IsWeaklyTracked) { trackedObject.ConvertToNew(); } else if (trackedObject.IsDeleted) { trackedObject.ConvertToPossiblyModified(); } else if (trackedObject.IsRemoved) { trackedObject.ConvertToNew(); } else if (!trackedObject.IsNew) { throw Error.CantAddAlreadyExistingItem(); } }
private void TrackUntrackedObjects(MetaType type, object item, Dictionary <object, object> visited) { if (!visited.ContainsKey(item)) { visited.Add(item, item); TrackedObject trackedObject = this.tracker.GetTrackedObject(item); if (trackedObject == null) { trackedObject = this.tracker.Track(item); trackedObject.ConvertToNew(); } else if (trackedObject.IsDead || trackedObject.IsRemoved) { return; } foreach (RelatedItem item2 in this.services.GetParents(type, item)) { this.TrackUntrackedObjects(item2.Type, item2.Item, visited); } if (trackedObject.IsNew) { trackedObject.InitializeDeferredLoaders(); if (!trackedObject.IsPendingGeneration(trackedObject.Type.IdentityMembers)) { trackedObject.SynchDependentData(); object obj3 = this.services.InsertLookupCachedObject(trackedObject.Type, item); if (obj3 != item) { TrackedObject obj4 = this.tracker.GetTrackedObject(obj3); if (!obj4.IsDeleted && !obj4.CanInferDelete()) { if (!obj4.IsDead) { throw new DuplicateKeyException(item, Strings.CantAddAlreadyExistingKey); } } else { trackedObject.ConvertToPossiblyModified(obj4.Original); obj4.ConvertToDead(); this.services.RemoveCachedObjectLike(trackedObject.Type, item); this.services.InsertLookupCachedObject(trackedObject.Type, item); } } } else { object cachedObjectLike = this.services.GetCachedObjectLike(trackedObject.Type, item); if (cachedObjectLike != null) { TrackedObject obj6 = this.tracker.GetTrackedObject(cachedObjectLike); if (obj6.IsDeleted || obj6.CanInferDelete()) { trackedObject.ConvertToPossiblyModified(obj6.Original); obj6.ConvertToDead(); this.services.RemoveCachedObjectLike(trackedObject.Type, item); this.services.InsertLookupCachedObject(trackedObject.Type, item); } } } } foreach (RelatedItem item3 in this.services.GetChildren(type, item)) { this.TrackUntrackedObjects(item3.Type, item3.Item, visited); } } }