简体   繁体   English

.Net Core 2.0数据库第一种方法Mysql DB的Scaffold-DbContext

[英].Net Core 2.0 Database First Approach Scaffold-DbContext of Mysql DB

I am developing WEB API in .Net Core 2.0 with MySQL DB. 我正在使用MySQL DB在.Net Core 2.0中开发WEB API。 I am trying to scaffolding MySQL DB. 我正在尝试搭建MySQL DB。 I have follow This link (MySQL Official Site) but when I fire scaffolding command I getting error both I have mention below, please do let me know if I am doing anything wrong. 我已经关注了这个链接(MySQL官方网站),但是当我解除脚手架命令时我得到了错误,我在下面提到过,如果我做错了什么,请告诉我。 Command For Scaffolding(firing in Package Manager Console) 脚手架命令(在程序包管理器控制台中触发)

Scaffold-DbContext "server=localhost;port=3306;user=root;password=darshan7826;database=sakila" MySql.Data.EntityFrameworkCore -OutputDir sakila -f

Error on executing above command 执行上述命令时出错

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.

挖掘后我发现.Net Core 2.0 Mysql Connector工作不正常,经过一些搜索和RnD我发现Pomelo Foundation从Stack溢出后我尝试了它并且它有效。

Taking a look at the official sourcecode for the MySQL Connector for .Net , you can see that it's not complete yet due to this: 看一下.NetMySQL连接器的官方源代码,您可以看到它还没有完成,原因如下:

public DatabaseModel Create(string connectionString, 
    IEnumerable<string> tables, IEnumerable<string> schemas)
{
  throw new NotImplementedException();
}

You may want to open up a bug report on the official bug tracker . 您可能想要在官方错误跟踪器上打开错误报告。

Alternatively, there does seem to be a much newer beta version that you could look at trying. 或者,似乎有一个更新的测试版,你可以尝试。 https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore/8.0.9-dmr https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore/8.0.9-dmr

You should run this (from Package-Manager-Console): 你应该运行它(从Package-Manager-Console):

Scaffold-DbContext "Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;" 
MySql.Data.EntityFrameworkCore -OutputDir Models

or use: 或使用:

dotnet ef dbcontext scaffold

Note : You should be at the project in which MySql.Data.EntityFrameworkCore NuGet package has been added. 注意 :您应该在已添加MySql.Data.EntityFrameworkCore NuGet包的项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Asp.net Core 2.0与MYSQL的实体框架数据库优先方法 - Asp.net core 2.0 with entity framework database first approach with MYSQL 运行 Scaffold-DbContext 时出现超时错误 - Timeout error on running Scaffold-DbContext 如何使用ASP Net Identity 2.0,MySQL和数据库优先方法注册用户? - How to register a user using asp net identity 2.0, mysql and database first approach? 无法将 MySQL 数据库搭建到我的 .net 核心 Web API 项目中 - Failure to scaffold a MySQL database into my .net core Web API project 从WebAPI使用的Net Core 2.0 Mysql数据库(新手) - Net Core 2.0 Mysql database to consume from WebAPI(newbie) 使用 MySql 数据库而不是具有 .net 核心的 Sql 服务器时无法创建 dbcontext - Cannot create dbcontext when using a MySql database instead of Sql Server with .net core .NET Core中用于MySQL DB 5.7的Azure数据库瞬态处理 - Azure database for MySQL DB 5.7 Transient handling in .net core 无法在 .net core 3.1 中为 MySQL 中的“datetime”类型列提供支架 - Unable to scaffold “datetime” type columns from MySQL in .net core 3.1 .net核心数据库托管的最佳方法是什么? - What is the best approach for .net core database hosting? 带有MySQL DB的.NET Core 2.0 WebAPI-dotnet发布-运行.dll时连接字符串为null - .NET Core 2.0 WebAPI with MySQL DB - dotnet publish — Connection string null when running .dll
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM