Step 1: Create the project.
Select the type of project
Select the framework version and type
Step 2: Import the packages
Enter the NuGet package manager
The database package must be the same as the database type where the script was used.
These 2 packages are essential:
Step 3: Generate models and database context
The following command must be entered in the console:
Scaffold-DbContext "Data Source={Server Name};Initial Catalog=DbFirstEFTutorial;Integrated Security=True; TrustServerCertificate=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
The string format is:
Scaffold-DbContext + Connection string + DB package + Folder where the models are generalized.
Step 4: Correct sensitive information warning caused by database context
The text string in line 24 is passed to the appsettings.json file, and lines 9-11 and 22-24 are removed.
Context is added to program.cs so that it can be recognized
Step 5: Creating views and controllers using Scaffolding
Files that are generated and end in Controller.cs are moved to the Controllers folder so that they can be recognized.
The _Layout.cshtml navbar accesses are added to be able to access the generated views.
Resultados: