Try our conversational search powered by Generative AI!

Episerver - Automatically delete Properties from Episerver when deleted in code

Ayo
Ayo
Vote:
 

I'm working on my first EPI Server project and I have noticed that when I create a property on a 'Page Type' in C# Code, compile it, I can see the properties in Episerver.

However when I then delete that property in code the property still appears in the back office, and I have to manually delete it in the admin section.

Is there a setting in Epi server that will automatically delete properties from the EPI server database when they are removed from code? It seems very strange that you would have to delete the properties one by one every time you make a change to a Page Type.

#188366
Feb 21, 2018 11:31
Vote:
 

Unfortunately such a feature does not exist today, atleast not as far as I am aware. It is possible to do it via code though. I haven't tried it personally but this might be what you are looking for: https://world.episerver.com/blogs/Per-Nergard/Dates/2013/3/Plugin-for-deleting-missing-properties/.

#188372
Edited, Feb 21, 2018 13:47
Ayo
Vote:
 

Thanks for your Reply Jonathan, like I said this is my first episerver project so I'm not entierly sure how the plugin system works yet. Can you point me to a link that would show me what I need to know to use that plug in?

Also that looks like it was from 2013, will older plugins work with newer versions of episerver?

#188373
Feb 21, 2018 13:50
Vote:
 

I don't know if it will work out of the box, you might need to update some bits if some of the repositories used have been changed or something like that. I would download the code, look at it and add it to my repository if I thought it fitted if I were you. There are a few different blog posts on how to create your own plugin, for instance: https://www.dcaric.com/blog/episerver-how-to-create-gui-plugins-using-mvc. Hope it works out!

#188374
Feb 21, 2018 14:12
Vote:
 

Hi

It's been a while since I worked with this, but it's not quite as straight forward. How it works is that a property that has been remove from the code will be deleted from the database, but only if there are no values stored on that property on any content on the site. This is a safety measure. Consider, for instance, if a mistake happens during a deploy. Maybe an old version of a dll, one that doesn't have a newer property, is used on the site. What would happen without this check is that a whole bunch of content would be deleted, without any option of restoring it (barring a full database restore from backup).

This article might explain som more, https://world.episerver.com/documentation/developer-guides/CMS/Content/Refactoring-content-type-classes/.

Regards

Per Gunsarfs

#188384
Feb 21, 2018 16:07
Ayo
Vote:
 

Hi Per,

I can understand the safty reason however I still think there should be that option, with out having to write code to do it your self. If you are deleting a property, you don't want it any more, you don't want the data you don't want it in you code, you want it gone. 

In my situation I am adding some new features, but something has changed and we are going to do things in a slightly diffrent ways so I have lots and lots of properties from severy types and the only way to remove them is manually through the UI.... 

Then.... I have to go to our pre-live enviroment and do it all again.... (or have to restore the database from another enviorment, which is not what we want to do) - I am new to episerver so I will reserve judgement, but from my point of you this is a very silly and simple feature that Epi Server is missing..looking on line lots of people are asking the same question.

#188386
Feb 21, 2018 16:57
Vote:
 

In situations such as this I would write a migration for it so it can be run on different environments.

It isn't much code to write, just load those content types from the IContentTypeRepository, call the function ResetContentType and save.The extra caution is for projects once they go live but until then just reset. laughing

#188423
Feb 22, 2018 17:34
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.