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 DetachInternal(TEntity Entity) { DetachInternalUpdateAllRelated(Entity); EntityKeyManager.Remove(Entity); EntityChangeTracker.UnTrack(Entity); if (!Entity.IsUnchanged()) { Context.ChangeTracker.UnTrack(Entity); } Entity.Detached(); }