NetCore +EF+Mysql 从数据库生成实体类到项目

转载自:https://www.cnblogs.com/yangjinwang/p/9516988.html

1.点击“工具”->“NuGet包管理器”->“程序包管理器控制台”

分别安装以下几个包

 Mysql 版本:

Install-Package MySql.Data.EntityFrameworkCore -Pre
Install-Package Pomelo.EntityFrameworkCore.MySql
Install-Package Microsoft.EntityFrameworkCore.Tools
Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design

Sql server 版本:
Install-Package Microsoft.EntityFrameworkCore
Install-Package Microsoft.EntityFrameworkCore.SqlServer
Install-Package Microsoft.EntityFrameworkCore.Tools
Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design

2.在程序包包管理器控制台   中执行以下语句生成 实体类
--mysql 版本:
Scaffold-DbContext "server=.;userid=tech5_kj;pwd=xxx;port=3306;database=tech5_kj;sslmode=none;" Pomelo.EntityFrameworkCore.MySql -OutputDir Models -Force

或者

Scaffold-DbContext "server=.;userid=tech5_kj;pwd=xxx;port=3306;database=tech5_kj;sslmode=none;" Pomelo.EntityFrameworkCore.MySql -OutputDir Models -UseDatabaseNames -Force

--sql server 版本


Scaffold-DbContext "Data Source=.;Initial Catalog=EFCore_dbfirst;User ID=sa;Password=sa.123" Micro
posted @ 2021-02-23 15:48  gygang  阅读(261)  评论(0编辑  收藏  举报