In this video we will discuss the concept of Migrations in Entity Framework Core.
Text version of the video
https://csharp-video-tutorials.blogsp...
Slides
https://csharp-video-tutorials.blogsp...
ASP.NET Core Text Articles & Slides
https://csharp-video-tutorials.blogsp...
ASP.NET Core Tutorial
https://www.youtube.com/playlist?list...
Angular, JavaScript, jQuery, Dot Net & SQL Playlists
https://www.youtube.com/user/kudvenka...
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.
asp.net core docker Entity framework core migrations | |
| 265 Likes | 265 Dislikes |
| 24,186 views views | 524K followers |
| Science & Technology | Upload TimePublished on 30 Apr 2019 |
Related keywords
wcf vs web api,ajax meaning,csharp-video-tutorials.blogspot,webkinz,central park 5,csharp string format,webadvisor,asp.net core github,craigslist nj,wcf one piece,asp.net core 3,server status,ajax fc,ajax players,server jobs nyc,asp.net core swagger,credit karma,weber grill parts,webtoon,csharp corner,mvc design pattern,asp.net machine account,server error in '/' application,servers for minecraft,asp.net core dependency injection,asp.net core 3.0,wcf ria services,calculator,ajax ontario,asp.net mvc tutorial,asp.net core 3 release date,server job description,asp.net cos'è,csharp assembly,webcam,mvc hours,webmd symptom,csharp array,asp.net core web api,ajax jquery,wccftech,craigslist ny,csharp enum,ajax call,asp.net core 2. guida completa per lo sviluppatore,asp.net core,server pro,server status ffxiv,asp.net zero,cheap flights,csharp foreach,webcrims,server memes,asp.net core hosting,chase,serverless architecture,server resume,wcf c#,server books,mvcc connect,webmd,csharp to json,college football,ajax deadpool,csharp dictionary,server jobs,cvs,cnn,website,mvc tutorial,website builder,costco hours,asp.net web api,wcf service application,server side rendering,weber grills,serverless,wcf soap,mvc nj,wcf cat,asp.net core download,csharp to vb.net,cool math games,wcf test client,webster bank,citibank,asp.net core identity,ajax parking,webstaurant,asp.net core logging,mvconnect,cunyfirst,ajax post,asp.net guida,wcf nba,csharp download,wcfi foundation,csharp online,ajax jersey,csharp operator,wcf authentication,asp.net core razor pages,server duties,asp.net core environment variables,csharp random,http://asp.net,server 2019,chernobyl,web of dreams,century 21,serverminer,ajax cleaner,webassign,mvcsd,mvcsc,asp.net core configuration,csharp list,ajax marvel,asp.net tutorial,asp.net mvc,mvc medical,asp.net core tutorial,wcfm,ajax roster,mvc architecture,wcfs international curriculum,mvc2,asp.net core mvc,ajax soccer,chase online,server hosting,wcf api,costco,wcfi,server jobs near me,webex,ajax dish soap,capital one,server rack,csharp interface,craigslist,ajax tavern,webroot,ajax javascript,ajax request,wcf dragon ball,asp.net core 2.2,webster,asp.net core signalr,mvc framework,ajax paving,mvc near me,ajax greek,csharp tutorial,mvc pattern,asp.net identity,mvcu,asp.net core middleware,mvc map,csharp online compiler,wcf web service,asp.net download,wcf 2019 nba,mvc webadvisor,csharp switch,web store,mvcc,webmail,mvci,csharpstar,mvctc,wcf tutorial,
Không có nhận xét nào:
Đăng nhận xét