

Applying Created MigrationĪfter we have successfully created our migration, we have to apply it for changes to take effect in the database. As an opposite action, the Down() method will execute commands when we remove this migration (in this case it will just drop this created table). The Up() method consists of commands that will be executed when we apply this migration. This file has two methods conveniently named Up() and Down. Protected override void Down(MigrationBuilder migrationBuilder) Table.PrimaryKey("PK_Student", x => x.StudentId) IsRegularStudent = table.Column(nullable: false, defaultValue: true) Name = table.Column(maxLength: 50, nullable: false), StudentId = table.Column(nullable: false), Protected override void Up(MigrationBuilder migrationBuilder) So, if you have followed all the steps from the previous articles, the content of the InitialMigration file should look like this: public partial class InitialMigration : Migration The other two files: InitialMigration and InitialMigration.Designer are files that contain and describe the newly created migration. The ApplicationContextModelSnapshot.cs file holds the model of the database and it is updated every time a new migration is added. After that, it creates three different files in the Migrations folder: The first thing it does is inspect our class, associated entity classes (in this case only the Student class), and any configuration we applied. Actions that Take Place Behind the SceneĪfter we execute the Add-Migration command EF Core does several things behind the scenes to prepare our migration. NET/C# content and get paid? > JOIN US! Add-Migration InitialMigrationĪfter we press the Enter key, our migration will be completed.

Ef core sqlite tutorial code#
Wanna join Code Maze Team, help us produce more awesome. If you are following this series from the start, then you already have the Microsoft.EntityFrameworkCore library installed.
Ef core sqlite tutorial install#
Therefore, we have to install the library.
Ef core sqlite tutorial update#
Using migrations is a standard way to create and update a database with Entity Framework Core. To see all the basic instructions and complete navigation for this series, visit Entity Framework Core with ASP.NET Core Tutorial. To download the source code for this article, you can visit our GitHub repository.
