Skip to content

ZahidIqbal78/cs_aspcore_webapi_databasefirst

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

ASP.NET Core WebAPI using Database First Approach

Solution consists of 2 projects currently. One is the WebAPI ofcourse, and another is the Data Access layer, which contains the models and DbContext generated from the database.

Adventure Works 2017 database is being used.

How to create the DbContext and Models from Existing Database

In this solution, a separate class library project (.NET Core) is used to store the model and DbContext. To generate or reverse engineer the model, install EntityFrameworkCore using Nuget Package Manager. Once installed, install the sql server database provider using the package manager console.

Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 2.2.2

Then scaffold the models using the following:

Scaffold-DbContext "Server=[server];Database=[database_name];Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir [output_folder_name]