DB or Database First Approach in Entity Framework Core & Asp.Net Core 5 & 3.1 to Create Models

preview_player
Показать описание
DB or Database first approach in Entity Framework Core example to fetch data from a table and generate the model from database entity framework core. In this tutorial, you can find everything related to DB first approach in Asp.Net Core 5 and 3.1. If you are using .Net core 3.1 or 3.0 then make sure to install the latest packages which we have defined in this database first approach in the Entity Framework core tutorial. In this video, you will also learn to Create Models from an existing database using EF Core.

Step 1: Install the below packages from the Nuget Package Manager console
1. Microsoft.EntityFrameworkCore​
2. Microsoft.EntityFrameworkCore.Design​
3. Microsoft.EntityFrameworkCore.SqlServer​
4. Microsoft.EntityFrameworkCore.Tools

Step 2: Add connectionString in the config file as explained in entity framework core database first approach tutorial

Step 3: Run the below command in Nuget Package Manager console:
Scaffold-DbContext "Server=.\SQLEXPRESS;Initial Catalog=WebAPI;MultipleActiveResultSets=true;User ID=sa;Password=123456;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models​

Step 5: Add Dependency Injection or Inversion of Control (IOC):
private readonly MyDbContext _dbContext;

Step 6: Create Action Method to get the Data from the database table

After following the above EF core steps you will be able to create the model from the database using entity framework core in Asp.Net Core 3.1 and 5.

Please find the Project and Notepad link below:

Go to this link to take the test to identify yourself.

Рекомендации по теме
Комментарии
Автор

Thanks for the wonderful session. It is very useful for beginner to learn to asp.net core Api DB first approach

jeyam
Автор

Hi sir, I started learning .Net framework first I have cover the C# basics then SQL basics what I have to learn please suggest next step, your comment will be very helpful

rushikeshsatkar
Автор

How can I update the Dbcontext I have added new tables in Db

rajashekhardommati