RUVIDEO
Поделитесь видео 🙏

Entity framework core migrations

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.
https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation=1

Text version of the video
https://csharp-video-tutorials.blogspot.com/2019/04/entity-framework-core-migrations.html

Slides
https://csharp-video-tutorials.blogspot.com/2019/04/entity-framework-core-migrations-slides.html

ASP.NET Core Text Articles & Slides
https://csharp-video-tutorials.blogspot.com/2019/01/aspnet-core-tutorial-for-beginners.html

ASP.NET Core Tutorial
https://www.youtube.com/playlist?list=PL6n9fhu94yhVkdrusLaQsfERmL_Jh4XmU

Angular, JavaScript, jQuery, Dot Net & SQL Playlists
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd


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.

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Entity framework core migrations», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.