【问题标题】:Entity Framework. Your Project References the latest version of entity framework error VS2017 MYSQL 8.0.12实体框架。你的项目引用了最新版本的实体框架报错VS2017 MYSQL 8.0.12
【发布时间】:2019-02-13 18:30:55
【问题描述】:

我有一个具有 Entity Framework 6.2 的 Visual Studio 2017 项目

尝试创建 edmx 文件时出现错误

您的项目引用了最新版本的实体框架; 但是,与此兼容的实体框架数据库提供程序 找不到您的数据连接版本

我遇到过很多次,但它总是通过使用连接器安装文件夹中的 dll 并对 app.config 进行一些更改来修复

但是我现在无法让它以这种方式工作。我不知道接下来要尝试什么...我正在使用 MYSQL 8.0.12

这是我的 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>
  <entityFramework>
    <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <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.12.0" newVersion="8.0.12.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

【问题讨论】:

  • 如果你有6.2,为什么重定向指向newVersion="6.0.0.0"
  • EFs nuget 包会在安装时添加。即使一切正常,它也一直如此。

标签: c# mysql entity-framework-6


【解决方案1】:

不确定这是否仍然解决不是。但是,以下解决方案可能对正在苦苦挣扎的人有所帮助。

您是否安装了任何版本的连接器都没有关系,因为它不会在 VS 2017 中自动引用。唯一重要的是“MySQL for Visual Studio”。

  1. 安装“MySQL for Visual Studio”(最好是任何最新版本 1.2.8 或 2.0.5) 如果您在尝试安装 2.0.5 时遇到任何问题,请点击此链接:https://forums.mysql.com/read.php?174,664930,664971

  2. 在您的项目中,将 Nuget 引用添加到“MySQL.Data.EntityFrameWork” (V 8.0.13 或更高版本)

默认会创建下面的 App.Config 文件

<?xml version="1.0" encoding="utf-8"?>
<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>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, 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.13.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
      </provider></providers>
  </entityFramework>
</configuration>

你去吧..它应该可以正常工作。我花了超过 2 天的时间,搜索整个谷歌(几乎)以发现所有的引用/方向/建议都指出“MySql.Data.Entity.EF6”.. 虽然所有而“MySql.Data.EntityFramework”在 VS 2017 中运行良好

【讨论】:

  • 这很有帮助。最重要的是,如果您要将项目从 MySql.Data 6.0.X 更新到 8.0.X,请删除您的 EntityFramework、MySql.Data 和 MySql.Data.EF6。浏览您的 App.Config 和 Web.Config 并删除与 MySql 和 entityFramework 相关的所有部分,但您可以保留的 connectionStrings 除外。然后,当您添加 EntityFramework 和 MySql.Data.EntityFramework 时,配置中的所有部分都是正确的。
  • 您需要卸载并重新安装 MySQL for Visual Studio 才能触发 Visual Studio 中的更新。现在,如果您在 View -> Server Explorer 中连接到您的数据库,您可以通过单击将出现在您的解决方案资源管理器中的蓝色 MySQL 应用程序配置工具按钮来配置您的 App.config。您的项目需要引用已安装的连接器文件夹中的 Entity Framework Nuget 以及 MySQL.Data 和 MySQL.Data.EntityFramework DLL。 dev.mysql.com/doc/visual-studio/en/…
猜你喜欢
  • 1970-01-01
  • 2016-10-17
  • 1970-01-01
  • 1970-01-01
  • 2017-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多