I’ve blogged previously about Adding a custom field into the commerce customer object via code. After a recent upgrade to commerce, our DataContext.Current.MetaClasses always returned null in our Intialization module until the commerce migration script was run.
A good example why you might want to use this is in your test server deployment. When you use a continuous integration process to deploy to a server, instead of using a central database server, you could delete and re-build the database on each deployment. You can then use fixtures to pre-populate your Episerver website with pages and blocks automatically.
As part of this process we want to include a test customer to be able to log-in. If your customer also has custom properties then you need to make sure they are run when the application launches.
If you have have a similar requirement pre-populating your objects before the migration script is run can be done.. it’s just not documented anywhere!
Luckily, within CustomerContext.Current.GetContactById() there’s a check to see if the customer object has been created yet, if not, it will run a command to update database script to create the Customer MetaData class