No Entity Framework provider found for 'MySql.Data.MySqlClient' ADO.NET provider

前端 未结 11 691
青春惊慌失措
青春惊慌失措 2020-11-29 04:45

I\'m trying to use Entity Framework with MySQL and I get the above error. I have the latest MySQL connector installed.

The full error reads:

No Entit         


        
相关标签:
11条回答
  • 2020-11-29 05:00

    In my case, it was a missing reference. When you upgrade to EntityFramework 6, you need to add a reference to the assembly

    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.

    When your app.config is good and all your references seem fine, it's a solution worth checking.

    0 讨论(0)
  • 2020-11-29 05:02

    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. Before adding the attribute everything would compile fine but crash at runtime.

    [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
    public class DemoContext : DbContext{}
    
    0 讨论(0)
  • 2020-11-29 05:04

    in EF5 or less, all ok. in EF6, you need to use mysql connector 6.8.x, and add DbConfigurationTypeAttribute to you DbContext:

    [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
    public class DemoContext : DbContext{}
    

    which MySqlEFConfiguration is in MySql.Data.Entity.EF6.dll in 6.8.x. Have a try!

    0 讨论(0)
  • 2020-11-29 05:04

    I just had the same situation when trying to configure Visual Studio Professional 2017 environment with MySQL, ADO.NET (Database First) and EF6.

    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.

    1. Uninstall/remove "Connector/NET" and "MySQL for Visual Studio" if installed.

    2. Install "MySQL for Visual Studio" v2.0.5 CTP (MySQL for Visual Studio). Note: Install MySQL for Visual Studio before Connector/NET.

    3. Install "Connector/NET" v6.9.10 (Connector/Net). 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.

    4. Download and Install "EntityFramework" v6.2.0 through NuGet.

    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.

    6. Add MySQL EF6 provider info inside App.config under entity framework providers as follow:

    <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. Hope this works for everybody, as it did for me today.

    References:

    1. Can't Create Entity Data Model - using MySql and EF6

    2. No Entity Framework provider found for 'MySql.Data.MySqlClient' ADO.NET provider

    0 讨论(0)
  • 2020-11-29 05:05

    You need to create this section in 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:

    <entityFramework>
      <!-- ... -->
      <providers>
        <provider invariantName="MySql.Data.MySqlClient"
                  type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
      </providers>
    </entityFramework>
    

    Thanks to elcool.

    0 讨论(0)
  • 2020-11-29 05:10

    May just MySql provider is installed in machine-config (e. g. by .net connector installer? Also the default connection factory should be something like "MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" i guess...

    0 讨论(0)
提交回复
热议问题