創建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