How to get MySQL working with Microsoft .NET’s Entity Framework 6

  1. Download and install the latest MySQL .NET Connector.
  2. Add [MySQL.Data] and [MySql.Data.Entity for EF6] assembly references for your .NET Framework version (hover over the assembly to see its framework version in its .dll path).
  3. Use NuGet Package Manager to install Entity Framework.
  4. Modify Web.config’s <entityFramework> section to MySQL values (this will avoid the “No Entity Framework provider found for the ADO.NET provider with invariant name ‘MySql.Data.MySqlClient’.” error):
      <defaultconnectionfactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6">
          <parameter value="v11.0"></parameter>
        <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>
  5. Add the following to Web.config’s <configuration> section:
    <system .data>
        <remove invariant="MySql.Data.MySqlClient"></remove>
        <add name="MySQL Data Provider"
             description="Data Provider for MySQL"
             type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></add>
      <add name="Storage"
           connectionString="server=localhost; User Id=user; Password=password; Persist Security Info=True; database=db_name;"
  6. For migrations to work, add this to your migration Configuration class’ constructor:
    SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());

Leave a Reply

Your email address will not be published. Required fields are marked *