Scaffold .net core 3.1 auto generate EF

New project

 
Open  Package Manager Console:

Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design -Version 3.0.0-preview8-19413-06

Install-Package Microsoft.EntityFrameworkCore.Tools -Version 3.0.0-preview8.19405.11

Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 3.0.0-preview8.19405.11


Using Scaffold Commend

Scaffold-DbContext "Server=LAPTOP-G08D86D1\SQLEXPRESS;Database=databasename;Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models



The Model is generated

It’s not good practice to have SQL Server credentials in C# class, considering the security issues. So, remove this OnConfiguring method from context file.

Remove the OnConfig

Add connection in ConfigureServices

Add in appsetting


Add new controller

Select  Model  and create


Created. 






留言

這個網誌中的熱門文章

香港袐密行動

要老是忘記, 我更記不起