/// <summary> /// Delete an item from the manager. /// Is a no-op for already deleted items. /// </summary> /// <param name="item">The item to delete.</param> public void Delete(TModel item) { using (ContextFactory.GetForWrite()) { // re-fetch the model on the import context. var foundModel = queryModel().Include(s => s.Files).ThenInclude(f => f.FileInfo).First(s => s.ID == item.ID); if (foundModel.DeletePending) { return; } if (ModelStore.Delete(foundModel)) { Files.Dereference(foundModel.Files.Select(f => f.FileInfo).ToArray()); } } }
/// <summary> /// Delete an item from the manager. /// Is a no-op for already deleted items. /// </summary> /// <param name="item">The item to delete.</param> public void Delete(TModel item) { using (var usage = ContextFactory.GetForWrite()) { var context = usage.Context; context.ChangeTracker.AutoDetectChangesEnabled = false; // re-fetch the model on the import context. var foundModel = queryModel().Include(s => s.Files).ThenInclude(f => f.FileInfo).First(s => s.ID == item.ID); if (foundModel.DeletePending) { return; } if (ModelStore.Delete(foundModel)) { Files.Dereference(foundModel.Files.Select(f => f.FileInfo).ToArray()); } context.ChangeTracker.AutoDetectChangesEnabled = true; } }