.net core using EF

This article has been VS2017 A Case Study
官方链接:[Getting Started with EF Core on ASP.NET Core with an Existing Database](https://docs.microsoft.com/zh-cn/ef/core/get-started/aspnetcore/existing-db?view=aspnetcore-2.1)
 
EF Core installation

Open the Tools> NuGet Package Manager> Package Manager Console

Run `Install-Package Microsoft.EntityFrameworkCore.SqlServe

Run `Install-Package Microsoft.EntityFrameworkCore.Tools`

 Run `Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design`

 

Generation model 
Open the Tools> NuGet Package Manager> Package Manager Console
Full data generation model:
Run  Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
 
Precautions
 Before using `Scaffold-DbContext`, solutions must be able to compile successful;
 -f allowed to overwrite an existing file under the Model;
 -t may specify one or more tables generated model, a plurality of table names separated by commas
 Comment out the method of the `OnConfiguring` Model Context file;
 建议使用另外其它项目生成好Model之后复制相关文件到当前项目,避免被覆盖
 

Guess you like

Origin www.cnblogs.com/tpcd1986/p/11314643.html