Using DB Migration

DB migration in Entity Framework helps you create a database or update a database schema during the application's development phase. We now have the required model and database context in place. We need to create the database now. Let's create the database in SQL Server Compact using the feature called database migration in Entity Framework. Follow these steps to do so:

  1. First, add the following XML tags to the csproj file by editing it:
  <ItemGroup>   
<DotNetCliToolReference
Include="Microsoft.EntityFrameworkCore.Tools.DotNet"
Version="1.0.0" />
</ItemGroup>
  1. Open Command Prompt and navigate to the project folder.

 

  1. Execute the following command to initialize the database for migration:
Execute the command to add migration

This command creates the Migration folder under the My Todo project and adds two classes to create tables and update the schema.

Files related to database migration
  1. Execute the following command to update the database:
Execute the command to update database

This command creates the database for our application as per the context and model.

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

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