具有MySql现有数据库的ASP.NET Core逆向工程师模型

时间:2018-07-04 02:27:03

标签: mysql asp.net-core scaffolding

我尝试使用EF Codefirst和现有的MySql数据库制作一个ASP.NET Core项目 当我尝试做反向工程师时(根据文章:Getting Started with EF Core on ASP.NET Core with an Existing Database

我有一个错误。 MySql包是:MySql.Data.EntityFrameworkCore -Version 8.0.11

我的数据库是:TEST 我的桌子是

CREATE TABLE USER (
  ID               BIGINT(20)  NOT NULL AUTO_INCREMENT,
  USERNAME         VARCHAR(50) NOT NULL,
  FIRSTNAME        VARCHAR(50) NOT NULL
) ENGINE=InnoDB; 

我使用以下命令:

Scaffold-DbContext "server=localhost;port=3306;user=root;password=123;database=TEST" MySql.Data.EntityFrameworkCore -OutputDir Models

错误:

System.NotImplementedException: The method or operation is not implemented.
   at MySql.Data.EntityFrameworkCore.Scaffolding.Internal.MySQLDatabaseModelFactory.Create(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, String namespace, String language, String contextDir, String contextName, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_1.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The method or operation is not implemented. 

有人知道我怎么卖这个吗? 如果像.NET Framework中的ASP.NET Web API这样的向导,有什么方法可以制作模型?

1 个答案:

答案 0 :(得分:0)

尝试一下对我有用。这也是NET Core兼容的MySQL连接器+ EF Core MySQL提供程序:

Pomelo.Data.MySql      
Pomelo.EntityFrameworkCore.MySql   
Pomelo.EntityFrameworkCore.MySql.Design