Entity Framework 6 and MySQL, model first

asp.net asp.net-mvc-3 c# entity-framework mysql

Popular Answer

Your connection string appears to be using the incorrect providerName; it should beSystem.Data.EntityClient .

Here is my app.config and how I eventually got my model-first code to work with MySQL:

<connectionStrings>
  <add name="MyEntities"
       connectionString="metadata=res://*/Data.Entity.Model.csdl|res://*/Data.Entity.Model.ssdl|res://*/Data.Entity.Model.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;Data Source=localhost;User Id=dbadmin;Password=password;Initial Catalog=database_name;&quot;"
       providerName="System.Data.EntityClient"/>
</connectionStrings>

Here is the entityFramework part in the event that doesn't work. You'll see that I utilized the codeConfigurationType attribute in the part that follows. There are alternative methods of accomplishing it, which you can learn about in the MySQL: Support for EF 6 documentation, but it adds dependency resolvers for MySQL.

<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
  <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"/>
  </providers>
</entityFramework>
5
2/9/2014 11:31:28 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow