What is DB first In Entity Framework .NET Core?
DB first we use where we already have the database and with the help of mS SQL Database we create the model class which hold the detail of the tables in the database. This approach is helpful where the DB change is minimal.Connect to MS SQL Database with EF Core in Asp.Net Core MVC
To connect to MS SQL server database using database first approach we ned to install the below mention three NuGet packages.
Package to install
1. Microsoft.EntityFrameworkCore.Tools
2. Microsoft.EntityFrameworkCore.Design
3. Microsoft.EntityFrameworkCore.SqlServer
After installing the NuGet Packages your packages section will looks as shown below.2. Microsoft.EntityFrameworkCore.Design
3. Microsoft.EntityFrameworkCore.SqlServer
Scaffold command syntax
Scaffold-DbContext "Server=<MS SQL Server Name>;Database=<Database name>;Trusted_Connection=True;TrustServerCertificate=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir data
Above syntax describe the complete command detail which we cna execute. Here we are having following items.
Server: <MS SQL Server Name>;
Database: <Database name>;
Trusted_Connection: True;
TrustServerCertificate:True;
To avoid the below mention error Trusted_Connection=True have been used.
Error!
A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)
Microsoft.EntityFrameworkCore.SqlServer: Represent the provider for the MS SQL server
-OutputDir data: This shown the folder in root. So, this folder will have all the table model class files and the DBContext class file after execution of the Scaffold command.
So before running the command we need to create a folder which we have defined in the Scaffold.
Now lets run the Scaffold command in Package Manager.
After successful execution. We will get out table object as shown below.

Scaffold command to update Table Object Scaffold-DbContext "Server=<MS SQL Server Name>;Database=<Database name>;Trusted_Connection=True;TrustServerCertificate=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir data -force