In this tutorial, you will learn some tips to help you spin up a brand new Episerver commerce website in code. When spinning up a new commerce database the default
MetaClasses are not installed. Only after you compile and run your site will they be installed. If you want to add additional meta-data to these commerce objects in code, this can cause a problem (read this tutorial to learn how to do that).
If you tried to run a custom initialization module when the site first runs, the
DataContext.Current.MetaClasses will return as
null. This means any custom code/scripts that you include in your solution that replies on these classes will fail when you rebuild the database. Fear not, there is a solution and In this tutorial, you will learn the secret. If this sounds useful, read on 🔥🔥🔥
CustomerContext.Current.GetContactById() there's a check to see if the customer object has been created yet. If not, the API in the background will run a command to update the database script to create the
Customer MetaData class. Basically, in your initialisation module, if you add this code snippet:
When the script runs all the meta-data classes will be created. Adding this snippet will mean your code never fails. A handy but useful tip. Happy Coding 🤘