In this tutorial, you will learn how to rename properties within Episerver. Having good naming conventions is an important aspect of good design. Content editors should be able to understand the purpose of each page or block. They should also be able to understand the purpose of each property. If a content editor does not know what a property does then you have a bad design.

Bad naming can result from different factors. The most common one is miscommunication when the project was built. Another common reason why you may want to rename a property is that the intention of the property changed over time. What once used to be a text string now needs to be a rich-text area.

Renaming a new property is very easy. Renaming an old property is more difficult. When happens when content has been stored within the database already. Renaming a property might cause database corruption. This is where Migration Steps can help.

If you need to change a property in either a page or a block. You can use a MigratonStep to migrate data from an old field into a new one.

The MigrationStep can be found within the 'EPiServer.DataAbstraction.Migration' namespace. Creating a migration step is very easy.

using EPiServer.DataAbstraction.Migration;

public class CustomMigrationStep: MigrationStep { public override void AddChanges() { // Rename Type ContentType("MyType").UsedToBeNamed("NewType");

    // Rename Property
    ContentType("Homepage")..Property("Title").UsedToBeNamed("HEading");
}

}

To create a custom migration step, inherited from 'MigrationStep'. OVerride the AddChnges() method. In this method, you can add the mapping code. This can be done using the ContentType() method. From ContentType() you can either get information about the page-type or, you can use the UsedToBeNamed() to rename things.

MigratonSteps can be really handy. To learn more you can read the official documentation here