简体   繁体   English

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

[英]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并按照以下步骤操作。

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

  2. 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。

  3. 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 ,但到目前为止这个列表是不准确的。

  4. Download and Install "EntityFramework" v6.2.0 through NuGet. 通过NuGet下载并安装“EntityFramework”v6.2.0。

  5. 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.dllC:\\Program Files (x86)\\MySQL\\Connector.NET 6.9.10\\Assemblies\\v4.5\\MySql.Data.Entity.EF6.dll

  6. 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> 

  1. Rebuild project. 重建项目。

And that was it. 就是这样。 VS2017 was ready to go for me. VS2017准备好了。 Hope this works for everybody, as it did for me today. 希望这对所有人都有效,就像今天对我一样。

References : 参考文献

  1. Can't Create Entity Data Model - using MySql and EF6 无法创建实体数据模型 - 使用MySql和EF6

  2. No Entity Framework provider found for 'MySql.Data.MySqlClient' ADO.NET provider 找不到'MySql.Data.MySqlClient'ADO.NET提供程序的实体框架提供程序

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) 对于EF4,使用Connector / NET 6.6.x(当前GA为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). 对于EF5,使用Connector / NET 6.7.x(当前GA为6.7.4)或Connector / NET 6.8.x(当前GA为6.8.3)。
  • For EF6, use Connector/NET 6.8.x (current GA is 6.8.3). 对于EF6,使用Connector / NET 6.8.x(当前GA为6.8.3)。

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 解决方案是

  1. Right click on the Solution (top level in the solution explorer) 右键单击解决方案(解决方案资源管理器中的顶级)
  2. Manage Nuget packages for solution 管理Nuget包以获得解决方案
  3. Go to Installed tab 转到已安装选项卡
  4. 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. 对于所有与EntityFramework相关的包(MySql.Data,MySql.Data.Entities,MySql.ConnectorNET.Entity和MySql.ConnectorNET.Data),选择它们,然后选择“管理”按钮。
  5. Enable each package for all projects. 为所有项目启用每个包。

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支持

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.

相关问题 未找到具有不变名称&#39;MySql.Data.MySqlClient&#39;的ADO.NET提供程序的实体框架提供程序-WCF - No Entity Framework provider found for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient' - WCF 具有不变名称“MySql.Data.MySqlClient”的 ADO.NET 提供程序未在计算机或应用程序配置文件中注册 - The ADO.NET provider with invariant name 'MySql.Data.MySqlClient' is either not registered in the machine or application config file 具有不变名称“MySql.Data.MySqlClient”的 ADO.NET 提供程序未在机器或应用程序配置文件中注册 - The ADO.NET provider with invariant name 'MySql.Data.MySqlClient' is either not registred in the machine or application config file 使用MySQL,具有不变名称&#39;MySql.Data.MySqlClient&#39;的ADO.NET提供程序未在计算机或应用程序配置文件中注册 - Using MySQL the ADO.NET provider with invariant name 'MySql.Data.MySqlClient' is either not registered in the machine or application config file 错误175:具有不变名称“MySql.Data.MySqlClient”的ADO.NET提供程序未在计算机或应用程序配置文件中注册 - Error 175: The ADO.NET provider with invariant name 'MySql.Data.MySqlClient' is either not registered in the machine or application config file ASP.NET,Visual Studio 2019,MySQL。找不到数据提供程序“Mysql.Data.MySqlClient” - ASP.NET, Visual Studio 2019, MySQL. The data provider 'Mysql.Data.MySqlClient' could not be found 在 Visual Studio 2019 的系统配置中找不到数据提供程序“Mysql.Data.MySqlClient” ASP.net - The data provider 'Mysql.Data.MySqlClient' could not be found in the system configuration on Visual Studio 2019 ASP.net Ado.net 中的多个数据库 Mysql 提供程序的实体框架 - Multiple Databases in Ado.net Entity framework for Mysql Provider 无法获取名为 MySql.Data.MySqlClient 的数据提供者的提供者工厂 - Cannot obtain provider factory for data provider named MySql.Data.MySqlClient 即使已更改,实体框架仍尝试连接到旧的ADO.NET提供程序 - Entity Framework keeps trying to connect to old ADO.NET provider eventhough it has been changed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM