簡體   English   中英

實體框架不適用於MySql

[英]Entity Framework will not work with MySql

我有Visual Studio Community 2015,並且有一個班級圖書館項目。 我已經通過nuGet添加了Entity Framework 6,Mysql.Data,MySql.Data.Entity和MySql.Net(甚至不確定是否需要)軟件包。

但是,當我通過向導將ADO.Net實體模型添加到項目中時,我得到了“選擇您的版本”的信息,但是卻收到一條錯誤消息,指出“您的項目引用了Entity Framework的最新版本;但是,一個實體找不到與該版本兼容的Framework數據庫提供程序用於您的數據連接。

我的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>
  <connectionStrings>
    <add name="MyContext" providerName="MySql.Data.MySqlClient" connectionString="server=localhost;port=3306;database=hapangodb;uid=root;password=********" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <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" />
    <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
      </provider></providers>
  </entityFramework>

<system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <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.9.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.6.4.0" newVersion="6.6.4.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>

我嘗試卸載並重新安裝所有mysql組件,但仍然遇到相同的問題。 多年來,我一直在使用帶有mysql的Entity Framework,沒有任何問題,但是自從有了新筆記本電腦以來,我似乎無法正常工作……

到底是怎么回事?

配置對我來說似乎正確。 僅出於測試目的,您是否嘗試過將下面的配置添加到您的machine.config文件中,看是否能成功?

<DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <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.9.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>

我已經解決了這個問題(為什么當您開始向人們介紹代碼問題時,您總是突然發現自己是為什么?

由於某種原因,我在App.config中有兩個mysql提供程序。 如您所見,其中一個只是EF6,另一個則是針對6.9.7.0。

我將EF6與SQL Server提供程序一起刪除了(因為無論如何我都不需要它),現在一切正常。

我冒昧地猜測,如果這兩個mysql提供程序相反,那么它也可能會起作用,因為它似乎一直在嘗試遇到的第一個mysql提供程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM