Delete dynamic content item
Hi, I am trying to delete an dynamic item from code. But after this code runs my item is still on the content page in published state. Please help me, what am I doing wrong?
var items = from item inthis.dynamicModuleManager.GetDataItems(this.entityType) where item.Status == ContentLifecycleStatus.Live && item.Visible select item;var entity= items.SingleOrDefault(el => el.GetValue<string>("Property") =="Value");if (entity== null) return;this.dynamicModuleManager.Lifecycle.Unpublish(entity);this.dynamicModuleManager.DeleteDataItem(entity);this.dynamicModuleManager.DeleteItem(entity);entity.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Deleted");this.dynamicModuleManager.SaveChanges();Best regards, Andrew
Is the variable hotel always null?
I don't see it assigned. Maybe it's just exiting?
Thanks for suggestion, Victor.
But it has been initialized. I ran my application in debug mode, and I can see that this line of code (this.dynamicModuleManager.SaveChanges();) invoked,
Hello,
You need to work with the Master version. Please try the following code:
var items = from item in this.dynamicModuleManager.GetDataItems(this.entityType) where item.Status == ContentLifecycleStatus.Master select item;var entity= items.SingleOrDefault(el => el.GetValue<string>("Property") =="Value");if (entity== null) return;this.dynamicModuleManager.Provider.DeleteDataItem(entity);this.dynamicModuleManager.SaveChanges();