创建class library并设置为启动项目
使用nuget控制台,设置当前项目为新建的class library
Install-Package Microsoft.EntityFrameworkCore.Tools
Install-package Microsoft.EntityFrameworkCore.SqlServer
Scaffold-DbContext "Server=.;Database=dbname;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
使用dotnet cli
dotnet ef dbcontext scaffold "Server=.;Database=dbname;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Models
参考:
http://www.entityframeworktutorial.net/efcore/create-model-for-existing-database-in-ef-core.aspx
https://stackoverflow.com/questions/39454545/the-term-scaffold-dbcontext-is-not-recognized-as-the-name-of-a-cmdlet-functio