private void RemoveInternal(TEntity Entity) { RemoveInternalUpdateAllRelated(Entity); if (Entity.HasTrackable()) { EntityChangeTracker.UnTrack(Entity); if (Entity.IsModified()) { Context.ChangeTracker.UnTrack(Entity); // remove from modified_entities } Entity.State = EntityState.Deleted; Context.ChangeTracker.Track(Entity); // this line of code must be executed after, state changes to deleted } else if (Entity.IsAdded()) { Context.ChangeTracker.UnTrack(Entity); EntityKeyManager.Remove(Entity); Entity.Detached(); } else { throw new CriticalException($"RemoveInternal {Entity}, State Must Be Unchanged Or Added Or Modified"); } }
private void CanAdd(TEntity Entity, out Dictionary <IEntityRelationForeignManager <TEntity>, ForeignStatus> ForeignStatuses) { if (!Entity.IsDetached()) { throw new EntitySetCanAddException($"{EntityType.Name} EntitySet Add Failed, {Entity} State Must Be Detached", 111); } if (Entity.EntitySet != null) { throw new CriticalException($"{EntityType.Name} EntitySet Add Failed, {Entity} Is Contained In Other EntitySet"); } if (EntityKeyManager.Find(Entity)) { throw new CriticalException($"{EntityType.Name} EntitySet Add Failed, Key Manager Find {Entity}"); } if (!EntityKeyManager.CanAdd(Entity)) { throw new EntitySetCanAddException($"{EntityType.Name} EntitySet Add Failed, Key Manager, New Key For {Entity} Has OverFlow", 112); } ForeignStatuses = GetAllForeignStatuses(Entity); if (!ForeignStatuses.IsValid()) { throw new EntitySetCanAddException($"{Entity} Has InValid Foreign[es] : " + string.Join(" | ", ForeignStatuses.Values), 113); } }
private void AddInternal(TEntity Entity, Dictionary <IEntityRelationForeignManager <TEntity>, ForeignStatus> ForeignStatuses) { Entity.EntitySet = this; EntityKeyManager.Add(Entity); AddInternalUpdateAllForeign(Entity, ForeignStatuses); AddInternalUpdateAllRelated(Entity); if (EntityKeyManager.IsExist(Entity)) { Entity.State = EntityState.Unchanged; UpdatedAllOrphan(Entity); Entity.OnPropertyChanged(Key.Name); } else if (EntityKeyManager.IsNew(Entity)) { Entity.State = EntityState.Added; Context.ChangeTracker.Track(Entity); Entity.OnPropertyChanged(Key.Name); } else { throw new CriticalException($"AddInternal {Entity}, Can Not Set EntityState"); } }
private void DetachInternal(TEntity Entity) { DetachInternalUpdateAllRelated(Entity); EntityKeyManager.Remove(Entity); EntityChangeTracker.UnTrack(Entity); if (!Entity.IsUnchanged()) { Context.ChangeTracker.UnTrack(Entity); } Entity.Detached(); }
internal void Accept(TEntity Entity) { if (Entity.EntitySet != this) { throw new EntitySetAcceptEntityException($"{Entity} EntitySet Not Equal To This EntitySet"); } if (!Entity.HasEditable()) { throw new EntitySetAcceptEntityException($"{Entity} Is Not Editable, State Must Be Unchanged Or Added Or Modified"); } if (!EntityKeyManager.Find(Entity)) { throw new EntitySetAcceptEntityException($"{typeof(TEntity).Name} Key Manager Not Find {Entity}"); } }
private void CanDetach(TEntity Entity) { if (Entity.IsDetached() || Entity.HasBusy()) { throw new EntitySetCanDetachException($"{EntityType.Name} EntitySet Detach Failed, {Entity} With {Entity.State} State Is Not Supported", 131); } if (Entity.EntitySet != this) { throw new EntitySetCanDetachException($"{EntityType.Name} EntitySet Detach Failed, {Entity} Is Contained In Other EntitySet", 132); } if (!EntityKeyManager.Find(Entity)) { throw new CriticalException($"{EntityType.Name} EntitySet Detach Failed, Key Manager Not Find {Entity}"); } if (IsRelated(Entity)) { throw new EntitySetCanDetachException($"{EntityType.Name} EntitySet Detach Failed, {Entity} Is Related", 133); } }
private void CanRemove(TEntity Entity) { if (!Entity.HasEditable() || Entity.HasBusy()) { throw new EntitySetCanRemoveException($"{EntityType.Name} EntitySet Remove Failed, {Entity} State Must Be Unchanged Or Added Or Modified", 121); } if (Entity.EntitySet != this) { throw new CriticalException($"{EntityType.Name} EntitySet Remove Failed, {Entity} Is Contained In Other EntitySet"); } if (!EntityKeyManager.Find(Entity)) { throw new CriticalException($"{EntityType.Name} EntitySet Remove Failed, Key Manager Not Find {Entity}"); } if (IsRelated(Entity)) { throw new EntitySetCanRemoveException($"{EntityType.Name} EntitySet Remove Failed, {Entity} Is Related", 123); } }