尝试使用 Scaffolding an Existing Database in EF Core
中的说明为现有的 MySql 数据库创建脚手架使用 EF Core 2.0 和 MySQL.DataEntityFrameworkCore{设计} 6.10.6。当我在包管理器控制台中运行以下(已编辑)命令时:
Scaffold-DbContext "server=111.2.33.44;port=3306;user=xxx;password=yyy;database=zzz" MySql.Data.EntityFrameworkCore -OutputDir DB -f
这应该让我得到 DB 中的脚手架文件,这是一个 C# 类库。
相反,我得到错误:
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.RelationalScaffoldingModelFactory.Create(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ModelScaffolder.Generate(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, String projectPath, String outputPath, String rootNamespace, String contextName, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, 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 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.
问题是,我不是要创建数据库,只是实现一个已经存在的数据库的接口。
这里有什么问题吗?
包
MySql.Data.EntityFrameworkCore
在我发帖的那一刻不支持脚手架NotImplementedException
。
Pomelo.EntityFrameworkCore.MySql
(阅读 Getting Started 部分关于手动添加 DotNetCliToolReference
到 Microsoft.EntityFrameworkCore.Tools.DotNet
)。
使用
Pomelo.EntityFrameworkCore.MySql
Package Manager Console
的命令将如下所示:
Scaffold-DbContext "your-mysql-connection-string" Pomelo.EntityFrameworkCore.MySql -OutputDir DB -f
非常感谢你,我很感激 这个命令 Scaffold-DbContext "your-mysql-connection-string" Pomelo.EntityFrameworkCore.MySql -OutputDir DB -f 是工作吗