无法创建实体数据模型 - 使用 MySql 和 EF6

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28241500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:18:13  来源:igfitidea点击:

Can't Create Entity Data Model - using MySql and EF6

mysqlentity-frameworkvisual-studio-2013mysql-connectorado.net-entity-data-model

提问by Idan Shechter

I'm trying to add an edmx Entity model to my C#/Web Project in Visual Studio 2013. My problem is that the file is not created.

我正在尝试将 edmx 实体模型添加到 Visual Studio 2013 中的 C#/Web 项目。我的问题是未创建该文件。

I do the following steps:

我执行以下步骤:

  1. Give the item a name
  2. Choose 'EF Designer from database'
  3. Choose the connection from the drop down (localhost) that already tested successfully connecting to MySQL databse
  4. The "Save connection settings in webc.config as" option is checked
  5. I click 'Next' AND the window disappeared and I get back to the code window
  1. 为项目命名
  2. 选择“数据库中的 EF 设计器”
  3. 从下拉列表 (localhost) 中选择已成功连接 MySQL 数据库的连接
  4. 选中“将 webc.config 中的连接设置另存为”选项
  5. 我点击“下一步”,然后窗口消失了,我回到了代码窗口

No edmx file is created.(although it works with SQL Server, but not for MySQL)

没有创建 edmx 文件。(虽然它适用于 SQL Server,但不适用于 MySQL)

I have Entity Framework 6.1.2installed, MySql.Data, MySql.Data.Entities, MySql.Data.Entity, MySql.Web-- all installed.

我已经Entity Framework 6.1.2安装了, MySql.Data, MySql.Data.Entities, MySql.Data.Entity, MySql.Web-- 都安装了。

I also rebuilt the project before trying to add an entity model file.

在尝试添加实体模型文件之前,我还重建了项目。

I've installed the latest MySQL package with the latest .NET connector.

我已经安装了最新的 MySQL 包和最新的.NET connector.

Running: Visual Studio 2013 on Windows 7.

运行:Windows 7 上的 Visual Studio 2013。

Any ideas how to solve this?

任何想法如何解决这个问题?

采纳答案by Loc Huynh

I solved this issue by following some steps below:

我通过以下一些步骤解决了这个问题:

  1. Uninstall MySql.Data.Entitiesfrom Nuget by using command below in Package Manager Console: Uninstall-Package MySql.Data.Entities

  2. Add project reference to the latest MySql.Data.Entity.EF6.dllfrom your MySql connector installation path at: C:\Program Files (x86)\MySQL\MySQL Connector Net 6.9.8\Assemblies\v4.5

  1. MySql.Data.Entities在包管理器控制台中使用以下命令从 Nuget卸载: Uninstall-Package MySql.Data.Entities

  2. MySql.Data.Entity.EF6.dll从 MySql 连接器安装路径添加对最新的项目引用:C:\Program Files (x86)\MySQL\MySQL Connector Net 6.9.8\Assemblies\v4.5

回答by Alfredo Rodriguez

I just had the same situation when trying to configure Visual Studio Professional 2017 environment with MySQL, ADO.NET (Database First) and EF6.

在尝试使用 MySQL、ADO.NET(数据库优先)和 EF6 配置 Visual Studio Professional 2017 环境时,我遇到了同样的情况。

Note: Please follow steps in the same order.

注意:请按照相同的顺序执行步骤。

  1. Uninstall/remove "Connector/NET" and "MySQL for Visual Studio" if installed.

  2. Install "MySQL for Visual Studio" v2.0.5 CTP (MySQL for Visual Studio). Note: Install MySQL for Visual Studio before Connector/NET.

  3. Install "Connector/NET" v6.9.10 (Connector/Net). https://i.stack.imgur.com/XOT1I.jpgNote: I tried using Connector/NET v6.8, v6.10 and v8 first, but none of them worked with Visual Studio 2017 and ADO.Net. Here you can find all Connector Versions and Compatibilities with Visual Studio IDEs, but so far this list is inaccurate.

  4. Create new Visual Studio Professional 2017 project.

  5. Download and Install "EntityFramework" v6.2.0 through NuGet, by going to Project Tab/Manage NuGet Packages/Browse -> Entity Framework.

  6. Add references to C:\Program Files (x86)\MySQL\Connector.NET 6.9.10\Assemblies\v4.5\MySql.Data.dlland C:\Program Files (x86)\MySQL\Connector.NET 6.9.10\Assemblies\v4.5\MySql.Data.Entity.EF6.dll; by Right Clicking over References inside Solution Explorer and selecting Add Reference/Browse ->Browse button.

  7. Add MySQL EF6 provider info inside App.config under entity framework providers as follow:

  1. 如果已安装,请卸载/删除“Connector/NET”和“MySQL for Visual Studio”。

  2. 安装“MySQL for Visual Studio”v2.0.5 CTP(MySQL for Visual Studio)。注意:在连接器/NET 之前为 Visual Studio 安装 MySQL。

  3. 安装“连接器/NET”v6.9.10(连接器/网络)。 https://i.stack.imgur.com/XOT1I.jpg注意:我首先尝试使用 Connector/NET v6.8、v6.10 和 v8,但它们都不适用于 Visual Studio 2017 和 ADO.Net。在这里您可以找到所有连接器版本和与 Visual Studio IDE 的兼容性,但到目前为止该列表是不准确的。

  4. 创建新的 Visual Studio Professional 2017 项目。

  5. 通过 NuGet 下载并安装“EntityFramework”v6.2.0,方法是转到 Project Tab/Manage NuGet Packages/Browse -> Entity Framework。

  6. 添加对C:\Program Files (x86)\MySQL\Connector.NET 6.9.10\Assemblies\v4.5\MySql.Data.dll和的 引用C:\Program Files (x86)\MySQL\Connector.NET 6.9.10\Assemblies\v4.5\MySql.Data.Entity.EF6.dll;通过右键单击解决方案资源管理器中的引用并选择添加引用/浏览 -> 浏览按钮。

  7. 在实体框架提供者下的 App.config 中添加 MySQL EF6 提供者信息,如下所示:

<entityFramework>
       <providers>
         <provider invariantName="MySql.Data.MySqlClient"
              type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
       </providers>
</entityFramework>

  1. Rebuild project by going to Build tab/Rebuild ProjectName.
  1. 通过转至 Build 选项卡/Rebuild ProjectName 重建项目。

And that's it. VS2017 is ready to go. Hope this works for everybody, as it did for me today.

就是这样。VS2017 已准备就绪。希望这对每个人都有效,就像今天对我一样。

References:

参考资料

  1. Can't Create Entity Data Model - using MySql and EF6

  2. No Entity Framework provider found for 'MySql.Data.MySqlClient' ADO.NET provider

  1. 无法创建实体数据模型 - 使用 MySql 和 EF6

  2. 找不到“MySql.Data.MySqlClient”ADO.NET 提供程序的实体框架提供程序

回答by Lars Meldg?rd

VS 2015 still has this bug. It is caused by version mismatch.

VS 2015 仍然有这个错误。它是由版本不匹配引起的。

On my system, I had MySQL Connector 6.9.6.
Issuing the command in NuGet Package Manger Console:

在我的系统上,我有 MySQL Connector 6.9.6。
在 NuGet 包管理器控制台中发出命令:

Install-Package MySql.Data.Entity

installs version 6.9.8 by default. Your connector must match the actual version of the NuGet Package.
You can download an updated version of the connector from: https://www.mysql.com/products/connector/

默认安装 6.9.8 版。您的连接器必须与 NuGet 包的实际版本相匹配。
您可以从以下位置下载连接器的更新版本:https: //www.mysql.com/products/connector/

Here select the "Ado.net driver for MySQL", and download the corresponding version (in this case 6.9.8). Reopen Visual Studio and now the wizard does not crash. No reboot required.

这里选择“Ado.net driver for MySQL”,下载对应的版本(本例为6.9.8)。重新打开 Visual Studio,现在向导不会崩溃。无需重启。

回答by Daniel Orlan

Taking suggestions about NuGet versioning from others answers. I solved this issue by deleting the .Dataand Data.Entitiy.EF6installed by Nuget.

从其他答案中获取有关 NuGet 版本控制的建议。我通过删除由 Nuget 安装的.Data和解决了这个问题Data.Entitiy.EF6

Then right click on References and browse for:

然后右键单击 References 并浏览:

C:\Program Files (x86)\MySQL\Connector.NET 6.9\Assemblies\v4.5\MySql.Data.dlland C:\Program Files (x86)\MySQL\Connector.NET 6.9\Assemblies\v4.5\MySql.Data.Entity.EF6.dll

C:\Program Files (x86)\MySQL\Connector.NET 6.9\Assemblies\v4.5\MySql.Data.dllC:\Program Files (x86)\MySQL\Connector.NET 6.9\Assemblies\v4.5\MySql.Data.Entity.EF6.dll

I was then able to complete the ADO.Net wizard, with the .edmx models.

然后,我能够使用 .edmx 模型完成 ADO.Net 向导。

回答by user942620

I was able to resolve this problem by performing the following:

我能够通过执行以下操作来解决这个问题:

  1. Open MySQL Installer and install the latest version of Connector/NET
  2. Uninstall / reinstall the latest version MySQL.Data.* packages with versions that match the version of the newly installed Connector/NET package
  3. Restart Visual Studios
  4. Rebuild solution
  1. 打开 MySQL Installer 并安装最新版本的 Connector/NET
  2. 卸载/重新安装最新版本的 MySQL.Data.* 包,其版本与新安装的 Connector/NET 包的版本相匹配
  3. 重新启动 Visual Studio
  4. 重建解决方案

回答by Lucassith

I know the solution.

我知道解决办法。

Nuget installs edge version of MySql.Data.* packages, while you probably have previous version of the connector (In my case packages were v. 6.9.6 and Connector was 6.9.5). This comes to the point where you have version mismatch.

Nuget 安装边缘版本的 MySql.Data.* 包,而您可能有以前版本的连接器(在我的情况下,包是 v. 6.9.6,连接器是 6.9.5)。这就到了版本不匹配的地步。

Be aware that if you use Install-Package MySql.Data.Entitiesin NuGet you will get even older version like 6.8.3, so you have to add the references by yourself and keep an eye on which one you are trying to add to your solution.

请注意,如果您在 NuGet 中使用Install-Package MySql.Data.Entities,您将获得更旧的版本,例如 6.8.3,因此您必须自己添加引用,并留意您要添加的引用解决方案。

回答by jetbadger

This is for an ASP.NET MVC application, which does not have an app.config file. I will not recount the failed attempts, but what worked for me was the following:-

这是针对没有 app.config 文件的 ASP.NET MVC 应用程序。我不会详述失败的尝试,但对我有用的是以下内容:-

  • With VS notrunning, download and install "MySQL for Visual Studio 2.0.5" - the latest version at time of writing.
  • Start VS2017 and uninstall the "MySql.Data.Entity" and "MySql.Data" NuGet packages, if they have been previously installed in VS2017.
  • Download and install the latest MySql connector/NET using the links above (version 8.0.13 at time of writing).
  • In your project add references to the "MySql.Data.dll" and "MySql.Data.EntityFramework.dll" dlls as described above by Lopez93, butN.B. the "MySql.Data.Entity.EF6.dll" mentioned did not exist in 8.0.13, only "MySql.Data.EntityFramework.dll".
  • Now edit the web.config file and make sure that in the section, there is this line
  • 在 VS运行的情况下,下载并安装“MySQL for Visual Studio 2.0.5”——撰写本文时的最新版本。
  • 启动 VS2017 并卸载“MySql.Data.Entity”和“MySql.Data”NuGet 包(如果它们之前已在 VS2017 中安装)。
  • 使用上面的链接下载并安装最新的 MySql 连接器/NET(撰写本文时为 8.0.13 版)。
  • 在您的项目中添加对“MySql.Data.dll”和“MySql.Data.EntityFramework.dll”dll 的引用,如 Lopez93 所述,但请注意,提到的“MySql.Data.Entity.EF6.dll”不存在于8.0.13,只有“MySql.Data.EntityFramework.dll”。
  • 现在编辑 web.config 文件并确保在该部分中有这一行

<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework">

<提供商invariantName = “MySql.Data.MySqlClient”类型= “MySql.Data.MySqlClient.MySqlProviderServices,MySql.Data。的EntityFramework”>

  • Remove or comment out any other '<provider invariantName="MySql.Data.MySqlClient"...' lines.

  • Rebuild the project.

  • 删除或注释掉任何其他 '<provider invariantName="MySql.Data.MySqlClient"...' 行。

  • 重建项目。

Try using the wizard again.

再次尝试使用向导。

For me this worked.

对我来说这有效。

Good luck!

祝你好运!

回答by randyh22

I ran into this issue upgrading from version 6 of MySql to version 8.0.17.0. I struggled with this for almost two days trying all of the old remedies until I came across this article. If you are using EF6 and version 8.0.? of MySql, according to this post:

我从 MySql 的第 6 版升级到 8.0.17.0 版时遇到了这个问题。我为此苦苦挣扎了将近两天,尝试了所有旧的补救措施,直到我看到了这篇文章。如果您使用的是 EF6 和 8.0 版。?MySql,根据这篇文章:



MySql.Data.Entity 6.10.7 与 MySql.Data 8.0.11 不兼容。

Oracle renamed the package to MySql.Data.EntityFramework for v8.x. You need to uninstall MySql.Data.Entity and install MySql.Data.EntityFramework.

Oracle 将该包重命名为 MySql.Data.EntityFramework for v8.x。您需要卸载 MySql.Data.Entity 并安装 MySql.Data.EntityFramework。



一旦我完成了这个简单的步骤,数据连接就开始工作,EDMX 设计器也开始工作(尽管我必须回到 2017 Visual Studio,因为在本文发布时,VS 2019 的设计器工具不可用。)

Hope this newer post helps some of you.

希望这篇较新的帖子对你们中的一些人有所帮助。

回答by Andy

I had the same problem using MySQL Connector 6.9.8.0. While all my versions matched, this still failed. I had installed a new version of Visual Studio AFTER the MySQL connector (From 2010 to 2013). For me, the solution was to uninstall the MySQL Connector for NET and then reinstall it (Exact same version). Then restart Visual Studio.

我在使用 MySQL Connector 6.9.8.0 时遇到了同样的问题。虽然我的所有版本都匹配,但这仍然失败。我在 MySQL 连接器之后安装了新版本的 Visual Studio(从 2010 年到 2013 年)。对我来说,解决方案是卸载 MySQL Connector for NET 然后重新安装它(完全相同的版本)。然后重新启动 Visual Studio。

Seems like this is another version of the same problem.

似乎这是同一问题的另一个版本。

回答by Intissar Ben Yedder

You can do this solution:

您可以执行此解决方案:

  1. Add a new empty EF model.
  2. In the emdx design rigth click and update the model from database.
  3. choose your database and the model will be generate.
  1. 添加一个新的空 EF 模型。
  2. 在 emdx design rigth 单击并从数据库更新模型。
  3. 选择您的数据库,然后将生成模型。

That's work for me :)

这对我有用:)