使用mySQL VisualStudio 2019的实体框架

时间:2019-12-12 23:05:17

标签: c# entity-framework mysql-connector

我收到此错误:

  

System.InvalidOperationException:'实体框架提供程序类型'MySql.Data.MySqlClient.MySqlProviderServices,MySql.Data.EntityFramework,Version = 8.0.18.0,Culture = neutral,PublicKeyToken = c5687fc88969c44d已注册为无法加载具有不变名称'MySql.Data.MySqlClient'的ADO.NET提供程序。确保使用了程序集限定名称,并且该程序集可用于正在运行的应用程序。

这是我的app.config文件。我不知道为什么我得到这个错误。几天以来,我一直在其他职位上没有提供任何帮助。

<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>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.0.18.0" newVersion="8.0.18.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EntityFramework">
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.18.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="StudentForYouEntities" connectionString="metadata=res://*/StudentForYouDataBase.csdl|res://*/StudentForYouDataBase.ssdl|res://*/StudentForYouDataBase.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=remotemysql.com;user id=dx01fvQECG;password=password;database=myDataBase;persistsecurityinfo=True&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

编辑:我发现当您尝试显示提供程序'System.Data.SqlClient'时,它与另一个项目(webapp)中的app.config有某种联系

1 个答案:

答案 0 :(得分:0)

好像您的应用程序无法加载MySql.Data.EntityFramework Version = 8.0.18.0,您是否尝试过通过NuGet安装它?

enter image description here