Search code examples
c#asp.netorchardcmsorchard-modulesorchardcms-1.9

Removing the TaxonomyField in the Migration


As I have been creating my own Orchard module I decided that I needed a couple of taxonomies via the AlterPartDefinition method in the ContentDefinitionManager(I've been following the Advanced Orchard course on Pluralsight) class. I later decided that I actually didn't need 3 taxonomies and now I wish to remove a couple of them. Below is some code how I added them.

 public int UpdateFrom10()
        {
            ContentDefinitionManager.AlterPartDefinition("ExercisePart", builder =>
            builder.WithField("Category", lvl => lvl.OfType("TaxonomyField")
            .WithSetting("DisplayName", "Category")
            .WithSetting("TaxonomyFieldSettings.Taxonomy", "Category")
            .WithSetting("TaxonomyFieldSettings.LeavesOnly", "False")
            .WithSetting("TaxonomyFieldSettings.SingleChoice", "False")
            .WithSetting("TaxonomyFieldSettings.Hint", "Select the category")
            ));
            return 11;
        }

How can I achieve my goal?

This is the course for those of you with access to pluralsight https://app.pluralsight.com/library/courses/adv-orchard/table-of-contents


Solution

  • Pretty simple

    ContentDefinitionManager.AlterPartDefinition("ExercisePart", builder =>
            builder.RemoveField("Category"));