This post details the setup process for Entity Framework code first migrations. Assume a new project with a User entity, with just 2 properties: Id and Name. The database schema is yet to be created. Creating the Schema Install the Entity Framework package, through the Nuget package manager or other means - more information on the package can be found on the project site Add a UserConfiguration file to control the mapping between entity and schema Add IDataContext and DataContext files, here every persisted entity must be declared as a DbSet and the corresponding configuration file must be added to the model builder as shown Add a connection string in the web config file, to an existing database In the package manager console, select the project where the Entity Framework package has been installed. Type update-database and run. This will create the schema in the database given in the connection string Updating the Schema Now, make a ...
My name is Ben and I am a software developer from Sussex, England. The purpose of this blog is to keep a record of technologies I utilise throughout my career as a software developer. I believe that not only will this further cement my understanding of these technologies, but also serve as a useful personal resource for future work.