NetCore + EFCore + SqlServer entity classes generated according to the project database

Reprinted from: https: //www.cnblogs.com/yangjinwang/p/9516988.html

1. Click on "Tools" -> "NuGet Package Manager" -> "Package Manager Console"

The following packages are installed

Mysql version:

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 version:

Install-Package Microsoft.EntityFrameworkCore
Install-Package Microsoft.EntityFrameworkCore.SqlServer
Install-Package Microsoft.EntityFrameworkCore.Tools
Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design

 

2. Execute the following statement in the program bag Manager console to generate entity classes
--mysql version:

Copy the code
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
Copy the code

--sql server version

Scaffold-DbContext "Data Source=.;Initial Catalog=EFCore_dbfirst;User ID=sa;Password=sa.123" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Force

 

Parameter Description:

Copy the code
-OutputDir *** entity files are stored in the file directory 
-ContextDir *** directory DbContext files stored 
-Context *** DbContext file name 
-Schemas *** need to generate a data table where the entity data model  -Tables *** We need to generate a data table entity data collection  - DataAnnotations - UseDatabaseNames used directly in the database table names and column names (some versions are not supported) -Force enforcement, rewriting existing entity file
Copy the code
 

Guess you like

Origin www.cnblogs.com/luckypc/p/10937598.html