[英]No Entity Framework provider found for 'MySql.Data.MySqlClient' ADO.NET provider
I'm trying to use Entity Framework with MySQL and I get the above error. 我正在尝试使用MySQL的实体框架,我得到上述错误。 I have the latest MySQL connector installed.
我安装了最新的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. 但这不起作用,因为它声称
invariant
名称是重复的。 And, if I actually iterate through the System.Data.Common.DbProviderFactories
I can see the last one is the MySQL provider: 而且,如果我实际遍历
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. 所以提供商在那里,但EF拒绝使用它。 Any ideas?
有任何想法吗?
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>
in EF5 or less, all ok. 在EF5或更低,一切都好。 in EF6, you need to use mysql connector 6.8.x, and add DbConfigurationTypeAttribute to you DbContext:
在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. 哪个MySqlEFConfiguration在6.8.x中的MySql.Data.Entity.EF6.dll中。 Have a try!
试试!
You need to create this section in config (EF 5): 您需要在config(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 。
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的地狱后,我使用Connector / NET v6.9.10并按照以下步骤操作。
Uninstall/remove "Connector/NET" and "MySQL for Visual Studio" if installed. 如果已安装,请卸载/删除“Connector / NET”和“MySQL for Visual Studio”。
Install "MySQL for Visual Studio" v2.0.5 CTP ( MySQL for Visual Studio ). 安装“MySQL for Visual Studio”v2.0.5 CTP( MySQL for Visual Studio )。 Note: Install MySQL for Visual Studio before Connector/NET.
注意:在Connector / NET之前为Visual Studio安装MySQL。
Install "Connector/NET" v6.9.10 ( Connector/Net ). 安装“Connector / NET”v6.9.10( 连接器/网络 )。 https://i.stack.imgur.com/XOT1I.jpg Note: 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.
https://i.stack.imgur.com/XOT1I.jpg注意:我首先尝试使用Connector / NET v6.8,v6.10和v8,但它们都没有工作在这里你可以找到所有连接器版本和兼容性与Visual Studio IDE ,但到目前为止这个列表是不准确的。
Download and Install "EntityFramework" v6.2.0 through NuGet. 通过NuGet下载并安装“EntityFramework”v6.2.0。
Add references to C:\\Program Files (x86)\\MySQL\\Connector.NET 6.9.10\\Assemblies\\v4.5\\MySql.Data.dll
and C:\\Program Files (x86)\\MySQL\\Connector.NET 6.9.10\\Assemblies\\v4.5\\MySql.Data.Entity.EF6.dll
. 添加对
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
。
Add MySQL EF6 provider info inside App.config under entity framework providers as follow: 在实体框架提供程序下的App.config中添加MySQL EF6提供程序信息,如下所示:
<entityFramework> <providers> <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" /> </providers> </entityFramework>
And that was it. 就是这样。 VS2017 was ready to go for me.
VS2017准备好了。 Hope this works for everybody, as it did for me today.
希望这对所有人都有效,就像今天对我一样。
References : 参考文献 :
Just adding a summary of versions (since I saw you are trying 6.2 which is way too old) 只需添加版本摘要(因为我看到你正在尝试6.2,这太旧了)
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. 我已经从EntityFramework 5.0更新到6.1和MySQL连接器6.8.3并且只需要添加属性来重新开始。 Before adding the attribute everything would compile fine but crash at runtime.
在添加属性之前,所有内容都可以正常编译但在运行时崩溃
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class DemoContext : DbContext{}
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,并为Visual Studio 1.2.3安装了MySql Connector 6.8.3和MySql。
The problem was that I had NuGet managing the packages, but only had them included in the main project. 问题是我让NuGet管理包,但只将它们包含在主项目中。 The solution was to
解决方案是
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 为了将来参考,这里是使用MySQL连接器/网络与EF 6的官方指南,其中包括所有必要的步骤(程序集,配置,等等): 第10章EF 6支持
从nuget https://www.nuget.org/packages/MySql.Data.Entity/安装最新版本
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
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很好并且你的所有引用都很好时,这是一个值得检查的解决方案。
Nevermind. 没关系。 I noticed that I had EF 6 installed.
我注意到我安装了EF 6。 I removed it and tried EF 5 instead (which NuGet says is the latest stable version) and it started working.
我删除它并尝试使用EF 5(NuGet说这是最新的稳定版本),它开始工作了。
Still, a more useful error message would have been nice! 不过,更有用的错误信息本来不错!
可能只是在机器配置中安装MySql提供程序(例如通过.net连接器安装程序?默认连接工厂应该类似于“MySql.Data.MySqlClient.MySqlClientFactory,MySql.Data,Version = 6.7.4.0,Culture = neutral, PublicKeyToken = c5687fc88969c44d“我猜......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.