Entity Framework defaultConnectionFactory for MySQL

.net, c#, entity-framework, mysql

Solution

The `name` property of the connectionString must be the same as your context. This works fine:

  <connectionStrings>
    <add name="NAMEOFYOURCONTEXT" providerName="MySql.Data.MySqlClient" connectionString="Server=localhost;Database=abc;Uid=root;Pwd='';" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6"></defaultConnectionFactory>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>
    </providers>
  </entityFramework>

Problem

The below configuration works fine when I specify the connectionString name as a parameter to the base constructor. Because I want to be able to change the default provider later on without recompiling, I want to set it in my `app.config` instead, but I have no idea what to provide as `type` for `defaultConnectionFactory`. ``` <connectionStrings> <add name="MySQL" providerName="MySql.Data.MySqlClient" connectionString="SERVER=localhost;DATABASE=abc;UID=root;PASSWORD=;" /> </connectionStrings> <entityFramework> <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, EntityFramework"></defaultConnectionFactory> <providers> <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider> </providers> </entityFramework> ``` Exception: Failed to set Database.DefaultConnectionFactory to an instance of the 'MySql.Data.Entity.MySqlConnectionFactory, EntityFramework' type as specified in the application configuration. See inner exception for details. Inner exception (translated, VS is set to English but some messages are still in my language): Could not load type "MySql.Data.Entity.MySqlConnectionFactory" in assembly "EntityFramework" The documentation states that the assembly name follows after the colon, thus I also tried `MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6`, giving me this exception: Format of the initialization string does not conform to specification starting at index 0. I'm using EF6, MySql.Data & MySql.Data.Entity.EF6 6.8.3.0.

Original source