前提条件:<1> 建好 .net core 项目
<2>点击工具=>nuget管理包=>控制台
<3>根据数据库安装以下不同的包
Mysql 版本:
Install-Package MySql.Data.EntityFrameworkCore -Pre Install-Package Pomelo.EntityFrameworkCore.MySql Install-Package Microsoft.EntityFrameworkCore.Tools Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design
在"程序包包管理器控制台"中执行以下语句生成实体类:
Scaffold-DbContext "server=.;userid=用户名;pwd=密码;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 版本:
Install-Package Microsoft.EntityFrameworkCore Install-Package Microsoft.EntityFrameworkCore.SqlServer Install-Package Microsoft.EntityFrameworkCore.Tools Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design
在"程序包包管理器控制台"中执行以下语句生成实体类:
Scaffold-DbContext "Data Source=192.168.12.34;Initial Catalog=数据库名称;User ID=登录名;Password=密码" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Force
Oracle 版本:
Install-Package Microsoft.EntityFrameworkCore Install-Package Oracle.EntityFrameworkCore Install-Package Microsoft.EntityFrameworkCore.Tools Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design
在"程序包包管理器控制台"中执行以下语句生成实体类:
Scaffold-DbContext -Connection "User Id=登录名;Password=密码;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.127.44)(PORT=1521))
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));"Oracle.EntityFrameworkCore -Force -Project DBLib -OutputDir ExtModels -Tables tablename