CTEC2402: Sofware Development Project

Database Seeding

The code first approach outlined here creates and re-cretes a database from your C# Model classes. The down side is that each time the model is changed all the data is lost. To re-populate the database when it is recreated you need to add a ProjectInitializer class to your models folder. Click on the link and save the text file as ProjectInitializer.cs. Make sure you change the name of the project in the namespace to match your project name.

In order to use this class, you need to modify your global.asax and create a new ProjectInitializer when your application starts (and if the model changes). Change it to somethging like:-


Please make sure that your project name is used in place of mvc4WebApplication, and the name of the class is not important you can spell it the british way ProjectInitialiser if you wish. Take out the old statement shown below.

Old Statement