Tags: Egenskaper

Renaming an Episerver page property using a migration step

Content types (like page types and block types) may be safely renamed, as long as you specify a GUID parameter in the ContentTypeAttribute of the class. The properties defined on a content type do not have the optional GUID parameter. If you simply rename a page property Episerver will just add another property to the same page.

To ensure that the existing property is renamed, and retain the value it had before it was renamed, you should use a migration step.

using EPiServer.DataAbstraction.Migration;

namespace Example
{
   public class RenamePropertyMigrationStep : MigrationStep
   {
      public override void AddChanges()
      {
         RenameProperty();
      }

      private void RenameProperty()
      {
         ContentType("ArticlePage")
            .Property("MainBody")
            .UsedToBeNamed("Text");
      }
   }
}

The code above will rename the property Text to MainBody for the page type called ArticlePage.

Remember that you must also change the name on the page type class. Changing this:

public virtual XhtmlString Text{ get; set; }

To this:

public virtual XhtmlString MainBody{ get; set; }