ASP .Net Core web API code first Entity Framework
ASP .Net Core web API code first Entity Framework
=====================
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Tools
Microsoft.EntityFrameworkCore.SqlServer
Add-Migration Initial
update-database
===================================================================================
=====================
===================================================================================
=====================
Introduction:
Demonstration of how to create a .Net Core Web API and use Code first approach
using Entity framework core and Swagger.
We will use Entity Framework core with a code-first approach to create the model
classes and database.
Additionally, we will utilize Swagger, an inbuilt feature of .NET Core Web API, to
simplify the request-response process.
STEPS::::::::::::::::::::::::::::
Creating a Project
- Create a new project using Visual Studio 2022, selecting the ASP.NET Core Web
API Core template.
- Uncheck the "Configure for HTTPS" option and proceeds with creating the project.
Swagger Integration
- Run the project, and Swagger opens in his browser.
- Swagger provides a user-friendly interface to interact with the API endpoints.
- By default, Swagger displays the "Weather Forecast" GET API, allowing users to
try it out and view default values.
Adding Packages
Add the following packages using the NuGet Package Manager:
Microsoft.EntityFrameworkCore - Version should be in accordance with Framewok
selected
Microsoft.EntityFrameworkCore.Tools
Microsoft.EntityFrameworkCore.SqlServer
Then, execute the "Update-Database" command to create the database based on the
migration script.