/// <summary> /// Detaches all passed entities from the current context. /// </summary> /// <param name="unchangedEntitiesOnly">When <c>true</c>, only entities in unchanged state get detached.</param> /// <param name="deep">Whether to scan all navigation properties and detach them recursively also. LazyLoading should be turned off when <c>true</c>.</param> /// <returns>The count of detached entities</returns> public static void DetachEntities <TEntity>(this HookingDbContext ctx, IEnumerable <TEntity> entities, bool deep = false) where TEntity : BaseEntity { Guard.NotNull(ctx, nameof(ctx)); using (new DbContextScope(ctx, autoDetectChanges: false, lazyLoading: false)) { entities.Each(x => ctx.DetachEntity(x, deep)); } }