Entity framework core migrations

  Рет қаралды 224,176

kudvenkat

kudvenkat

Күн бұрын

In this video we will discuss the concept of Migrations in Entity Framework Core.
Healthy diet is very important for both body and mind. We want to inspire you to cook and eat healthy. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking.
/ @aarvikitchen5572
Text version of the video
csharp-video-t...
Slides
csharp-video-t...
ASP.NET Core Text Articles & Slides
csharp-video-t...
ASP.NET Core Tutorial
• ASP.NET core tutorial ...
Angular, JavaScript, jQuery, Dot Net & SQL Playlists
www.youtube.co...
What is a migration in entity framework core
Migration is an entity framework core feature that keeps the database schema and our application model classes (also called entity class) in sync.
If you have not executed at-least the initial migration in your application you might get the following SqlException
SqlException: Cannot open database "EmployeeDB" requested by the login.
This is because we do not have the database created yet. One way to create the database is by
Creating a migration first and then
Executing that migration
To work with migrations, we can either use the Package Manager Console (PMC) or the .NET core command-line interface (CLI). If you are using Visual Studio like me, then use the Package Manager Console.
To launch Package Manager Console in Visual Studio, click on View - Other Windows - Package Manager Console
Common entity framework core migration commands
We will be using the following 3 common commands to work with migrations in entity framework core.
get-help about_entityframeworkcore - Provides entity framework core help
Add-Migration - Adds a new migration
Update-Database - Updates the database to a specified migration
Please note : You can use get-help command with any of the above commands. For example get-help Add-Migration provides help for Add-Migration command.
Creating Migration in Entity Framework Core
The following command creates the initial migration. InitialCreate is the name of the migration.
Add-Migration InitialCreate
When the above command completes, you will see a file in the "Migrations" folder that contains the name InitialCreate.cs. This file has the code required to create the respective database tables.
Please note : To have the command auto-completed in the Package Manager Console window, type part of the command and press the TAB key.
Update-Database in Entity Framework Core
We need to execute the migration code to create the tables. If the database does not exist already, it creates the database and then the database tables. For updating the database, we use Update-Database command. To the Update-Database command we may pass the migration name we want to execute. If no migration is specified, the command by default executes the last migration.
After the migration is executed, when you navigate to the application we no longer get the following SqlException
SqlException: Cannot open database "EmployeeDB" requested by the login.
This is because the EmployeeDB is created when the migration is executed. We can confirm this in SQL Server Object Explorer window in Visual Studio.
At the moment we do not have any data in the Employees table. In our next video, we will discuss how to seed the database table with initial data.

Пікірлер: 165
Entity framework core seed data
7:20
kudvenkat
Рет қаралды 130 М.
Repository pattern in asp net core
14:50
kudvenkat
Рет қаралды 303 М.
Brawl Stars Edit😈📕
00:15
Kan Andrey
Рет қаралды 44 МЛН
МАИНКРАФТ В РЕАЛЬНОЙ ЖИЗНИ!🌍 @Mikecrab
00:31
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 36 МЛН
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 183 М.
Entity Framework Migrations Explained
36:53
dotnet
Рет қаралды 31 М.
Entity Framework Core Tutorial - Everything You Need to Know to Get Started
40:56
The Common Entity Framework Mistake You MUST Fix
10:03
Nick Chapsas
Рет қаралды 51 М.
Manage user claims in asp net core
17:27
kudvenkat
Рет қаралды 65 М.
Create an EF Core Model from Database First (Scaffold DB Context)
4:56
Roberts Dev Talk
Рет қаралды 32 М.
Edit identity user in asp net core
17:14
kudvenkat
Рет қаралды 53 М.
Creating roles in asp net core
12:20
kudvenkat
Рет қаралды 133 М.
Making Entity Framework Core As Fast As Dapper
13:17
Nick Chapsas
Рет қаралды 86 М.
Brawl Stars Edit😈📕
00:15
Kan Andrey
Рет қаралды 44 МЛН