Connection With MSSQL Database Using ASP.NET Core 6 WEB API
In this video series you will learn how to connect your MSSQL Database to a .NET Core 6 Web API. This is a continuation of our TODO LIST application series , with focus on the backend/server side of the project.
Videos related to TODO APP :
1 . TODO HOME - • Master Angular as You Build a Fully F...
2. TODO LOGIN and Register - • TODO APP - CREATING A LOGIN AND REGIS...
3. TODO DATABASE - • TODO APP - How to Create MS SQL Datab...
4. TODO ADD and EDIT PAGE - • TODO APP - ADD AND EDIT PAGE - FRONT-...
Notes to follow to set up your database connection
- Installl the following packages to your project:
Install-Package Microsoft.EntityFrameworkCore.SqlServer
Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design
Install-Package Microsoft.EntityFrameworkCore.Tools
- Making database models from your database:
Scaffold-DbContext “Server={database servername}; Database={Database Name};Trusted_Connection=True;” Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
- Add The Following Connection String in your appsettings :
“ConnectionStrings”:{
“DefaultConnection” : “Server={database servername}; Database={Database Name};Trusted_Connection=True;”
}
- Run the following code in your package manager console :
add-migration initial
Run the following to update your database models run :
Scaffold-DbContext “Server={database servername}; Database={Database Name};Trusted_Connection=True;” Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
Please don't forget to LIKE , SHARE and SUBSCRIBE
#.NETCore6 #Full-stack-developer