Core Entity DBFirst
1.首先创建一个空的创建一个ASP.NET Core Web 应用
2.引入包,在程序包管理控制台运行命令
Install-Package Microsoft.EntityFrameworkCore.SqlServer
Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design
Install-Package Microsoft.EntityFrameworkCore.Tools-Pre
3.根据现有数据库生成实体和上下文,同样在程序包管理台运行命令
Scaffold-DbContext "server=DESKTOP-9HM12DD\YYBSQL;database=EFCoreDemo1;integrated security=SSPI;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
"server=DESKTOP-9HM12DD\YYBSQL;database=EFCoreDemo1;integrated security=SSPI;"为连接数据库字符串,如需其他数据库请自行修改,-OutputDir Models中Models为生成实体文件夹名。
后续如数据库新增或删减表,在命令后加-Force,即
Scaffold-DbContext "server=DESKTOP-9HM12DD\YYBSQL;database=EFCoreDemo1;integrated security=SSPI;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Force