找不到“MySql.Data.MySqlClient”ADO.NET 提供程序的实体框架提供程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15142841/
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
No Entity Framework provider found for 'MySql.Data.MySqlClient' ADO.NET provider
提问by Matt Burland
I'm trying to use Entity Framework with MySQL and I get the above error. I have the latest MySQL connector installed.
我正在尝试将 Entity Framework 与 MySQL 一起使用,但出现上述错误。我安装了最新的 MySQL 连接器。
The full error reads:
完整的错误如下:
No Entity Framework provider found for 'MySql.Data.MySqlClient' ADO.NET provider. Make sure the provider is registered in the 'entityFramework' section of the application config file.
However, I can't find anything that suggests just how you register it in the 'entityFramework' section.
但是,我找不到任何表明您如何在“entityFramework”部分注册它的内容。
Some other posts (example) suggest adding the provider to the system.Data
DbProviderFactories
section like this:
其他一些帖子(示例)建议将提供者添加到这样的system.Data
DbProviderFactories
部分:
<DbProviderFactories>
<add
name="MySQL Data Provider"
invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,
Version=6.2.3.0, Culture=neutral,
PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
But that doesn't work because it claims that the invariant
name is duplicated. And, if I actually iterate through the System.Data.Common.DbProviderFactories
I can see the last one is the MySQL provider:
但这不起作用,因为它声称invariant
名称是重复的。而且,如果我真的遍历System.Data.Common.DbProviderFactories
我可以看到最后一个是 MySQL 提供程序:
MySQL Data Provider
.Net Framework Data Provider for MySQL
MySql.Data.MySqlClient
MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d
So the provider is there, but EF refuses to use it. Any ideas?
所以提供者在那里,但 EF 拒绝使用它。有任何想法吗?
My full config looks like this:
我的完整配置如下所示:
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.data>
<!--<DbProviderFactories>
<add
name="MySQL Data Provider"
invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,
Version=6.2.3.0, Culture=neutral,
PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>-->
</system.data>
<connectionStrings>
<add name="myContext" connectionString="server=****;User Id=****;password=****;Persist Security Info=True;database=myDb"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>
采纳答案by Matt Burland
Nevermind. I noticed that I had EF 6 installed. I removed it and tried EF 5 instead (which NuGet says is the latest stable version) and it started working.
没关系。我注意到我安装了 EF 6。我删除了它并尝试使用 EF 5(NuGet 说它是最新的稳定版本)并且它开始工作了。
Still, a more useful error message would have been nice!
不过,更有用的错误消息会很好!
回答by AlexanderYao
in EF5 or less, all ok. in EF6, you need to use mysql connector 6.8.x, and add DbConfigurationTypeAttribute to you DbContext:
在 EF5 或更低版本中,一切正常。在 EF6 中,您需要使用 mysql 连接器 6.8.x,并将 DbConfigurationTypeAttribute 添加到您的 DbContext:
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class DemoContext : DbContext{}
which MySqlEFConfiguration is in MySql.Data.Entity.EF6.dll in 6.8.x. Have a try!
其中 MySqlEFConfiguration 在 6.8.x 中的 MySql.Data.Entity.EF6.dll 中。试试!
回答by Der_Meister
You need to create this section in config (EF 5):
您需要在配置(EF 5)中创建此部分:
<entityFramework>
<!-- ... -->
<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity" />
</providers>
</entityFramework>
Update:Use this definition for EF 6:
更新:将此定义用于 EF 6:
<entityFramework>
<!-- ... -->
<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
</entityFramework>
Thanks to elcool.
感谢elcool。
回答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 环境时,我遇到了同样的情况。
After going through hell with every connector/NET available, I got it to work with Connector/NET v6.9.10 and following the steps below.
在经历了每个可用的连接器/NET 之后,我让它与连接器/NET v6.9.10 一起工作,并按照以下步骤操作。
Uninstall/remove "Connector/NET" and "MySQL for Visual Studio" if installed.
Install "MySQL for Visual Studio" v2.0.5 CTP (MySQL for Visual Studio). Note: Install MySQL for Visual Studio before Connector/NET.
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 Here you can find all Connector Versions and Compatibilities with Visual Studio IDEs, but so far this list is inaccurate.
Download and Install "EntityFramework" v6.2.0 through NuGet.
Add references to
C:\Program Files (x86)\MySQL\Connector.NET 6.9.10\Assemblies\v4.5\MySql.Data.dll
andC:\Program Files (x86)\MySQL\Connector.NET 6.9.10\Assemblies\v4.5\MySql.Data.Entity.EF6.dll
.Add MySQL EF6 provider info inside App.config under entity framework providers as follow:
如果已安装,请卸载/删除“Connector/NET”和“MySQL for Visual Studio”。
安装“MySQL for Visual Studio”v2.0.5 CTP(MySQL for Visual Studio)。注意:在连接器/NET 之前为 Visual Studio 安装 MySQL。
安装“连接器/NET”v6.9.10(连接器/网络)。 https://i.stack.imgur.com/XOT1I.jpg注意:我首先尝试使用连接器/NET v6.8、v6.10 和 v8,但它们都不起作用在这里您可以找到所有连接器版本和与 Visual 的兼容性Studio IDEs,但到目前为止这个列表是不准确的。
通过 NuGet 下载并安装“EntityFramework”v6.2.0。
添加对
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
。在实体框架提供者下的 App.config 中添加 MySQL EF6 提供者信息,如下所示:
<entityFramework>
<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
</entityFramework>
- Rebuild project.
- 重建项目。
And that was it. VS2017 was ready to go for me. Hope this works for everybody, as it did for me today.
就是这样。VS2017 已经准备好迎接我了。希望这对每个人都有效,就像今天对我一样。
References:
参考资料:
回答by Fernando Gonzalez Sanchez
Just adding a summary of versions (since I saw you are trying 6.2 which is way too old)
只需添加版本摘要(因为我看到您正在尝试 6.2,这太旧了)
- For EF4, use Connector/NET 6.6.x (current GA is 6.6.6)
- For EF5, use Connector/NET 6.7.x (current GA is 6.7.4) or Connector/NET 6.8.x (current GA is 6.8.3).
- For EF6, use Connector/NET 6.8.x (current GA is 6.8.3).
- 对于 EF4,使用 Connector/NET 6.6.x(当前 GA 为 6.6.6)
- 对于 EF5,请使用 Connector/NET 6.7.x(当前 GA 为 6.7.4)或 Connector/NET 6.8.x(当前 GA 为 6.8.3)。
- 对于 EF6,请使用 Connector/NET 6.8.x(当前 GA 为 6.8.3)。
回答by Ken
I've updated from EntityFramework 5.0 to 6.1 and MySQL connector 6.8.3 and only had to add the attribute to get things going again. Before adding the attribute everything would compile fine but crash at runtime.
我已从 EntityFramework 5.0 更新到 6.1 和 MySQL 连接器 6.8.3,只需添加该属性即可再次运行。在添加属性之前,一切都可以正常编译,但在运行时会崩溃。
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class DemoContext : DbContext{}
回答by Ga???
I tried every different combination of config string and setup but I finally figured it out. My solution has the source code in one project and tests in another. I was using Entity Framework 6.1.1 and had installed MySql Connector 6.8.3 and MySql for Visual Studio 1.2.3.
我尝试了配置字符串和设置的各种不同组合,但我终于想通了。我的解决方案在一个项目中包含源代码并在另一个项目中进行测试。我使用的是 Entity Framework 6.1.1 并安装了 MySql Connector 6.8.3 和 MySql for Visual Studio 1.2.3。
The problem was that I had NuGet managing the packages, but only had them included in the main project. The solution was to
问题是我让 NuGet 管理包,但只将它们包含在主项目中。解决办法是
- Right click on the Solution (top level in the solution explorer)
- Manage Nuget packages for solution
- Go to Installed tab
- For all of the EntityFramework related packages (MySql.Data, MySql.Data.Entities, MySql.ConnectorNET.Entity and MySql.ConnectorNET.Data), select them then select the "Manage" button.
- Enable each package for all projects.
- 右键单击解决方案(解决方案资源管理器中的顶层)
- 管理解决方案的 Nuget 包
- 转到已安装选项卡
- 对于所有与 EntityFramework 相关的包(MySql.Data、MySql.Data.Entities、MySql.ConnectorNET.Entity 和 MySql.ConnectorNET.Data),选择它们然后选择“管理”按钮。
- 为所有项目启用每个包。
回答by Moayad Mardini
For future reference, here's the official guide on using MySQL Connector/Net with EF 6 which includes all the necessary steps (assemblies, configs, ...etc.): Chapter 10 EF 6 Support
为了将来参考,这里是在 EF 6 中使用 MySQL Connector/Net 的官方指南,其中包括所有必要的步骤(组装、配置等): 第 10 章 EF 6 支持
回答by Emanuele
Install latest version from nuget https://www.nuget.org/packages/MySql.Data.Entity/
从 nuget https://www.nuget.org/packages/MySql.Data.Entity/安装最新版本
回答by Mickael V.
In my case, it was a missing reference. When you upgrade to EntityFramework 6, you need to add a reference to the assembly
就我而言,这是一个缺失的参考。升级到 EntityFramework 6 时,需要添加对程序集的引用
System.Data.Entity
系统.数据.实体
I think it's because MySql.Data.Entity.EF6 inherits from a bunch of stuff in this assembly, that it did not for previous version of EF.
我认为这是因为 MySql.Data.Entity.EF6 继承了这个程序集中的一堆东西,它没有用于以前版本的 EF。
When your app.config is good and all your references seem fine, it's a solution worth checking.
当您的 app.config 很好并且您的所有引用看起来都很好时,这是一个值得检查的解决方案。