Database migration

We have created the business entity—the Employee class. Now, we can proceed with the migration. Migration is a two-step process: in the first step, we create the migration files. This can be done by executing the following command from the command prompt from the context of the project:

dnx ef migrations add InitialMigration

Database migration

This command will create the migration files in your project, as shown in the following screenshot:

Database migration

Then execute the following command to create the database:

Database migration

This command will read the migration files created in the previous step and create the database along with the associated tables:

Database migration

Run the application. You will get the following screen, where the user can enter the employee information in the form. As we are using the strongly typed model in our view, it takes the default values for all the properties. The Name and Designation are properties of type string and the default values are empty string for these fields, Salary is of type decimal and the default value for decimal is 0  hence 0 is shown in the form when it is loaded for the Salary field.

As there are no records, we are showing 0 records in the List of employees table:

Database migration

When you enter the information in the form and submit it, the information gets saved in the database and all the database records in the Employees table will be presented as follows:

Database migration

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset