How to connect db in ASP.NET Core MVC ?
Scaffold-DbContext "Data Source=DESKTOP-JMBSRJISQLEXPRESS;Initial Catalog=test;Integrated Security=True;TrustServerCertificate=True;"
Microsoft.EntityFrameworkCore.SqlServer
-OutputDir Models -Force
Shalki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
What problem did you encounter? If you want to know Ef and database in Mvc configuration and use, we usually:
-
Install
Microsoft.EntityFrameworkCore
andMicrosoft.EntityFrameworkCore.SqlServer
-
Configure the database context.
-
Add the connection string in the
appsettings.json
file. -
Register the database context in the
Program.cs
file. -
Create and apply migrations:
Add-Migration InitialCreate
Update-Database
For details, you can refer to this link.