Entity Framework 6 and MySQL, model first

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


I have a problem using Entity Framework 6 with MySQL and doing so using model/database-first technique in ASP.NET C# MVC 3.

The current situation is that I’m getting the error:

Keyword not supported.
Parameter name: metadata

The metadata is specified in the connection string in the web.config –file:

<add name="SiteNameContainer" 
  connectionString="metadata=res://*/Models. SiteName.csdl|
    res://*/Models. SiteName.ssdl|
    res://*/Models. SiteName.msl;
    provider connection string='server=;
    user id=fire;password=fire_db;
  providerName="MySql.Data.MySqlClient" />

I tried to remove the metadata-section in the connectionString, but then its saying that the keyword “provider” is not supported, and then “provider connection string” not supported.

I also have these 2 sections in my web.config file:

        <provider invariantName="MySql.Data.MySqlClient" 
            MySql.Data.Entity.EF6, Version=, 
            Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    <clear />
    <remove invariant="MySql.Data.MySqlClient" />
    <add name="MySql.Data.MySqlClient" 
        description=".Net Framework Data Provider for MySQL" 
        MySql.Data, Version=, Culture=neutral, 
        PublicKeyToken=c5687fc88969c44d" />

I have references to MySQL Net-connector 6.8.3 files (MySql.Data, MySql.Data.Entity.EF6, MySql.Web).

My requirments are that I must use MySQL and Entity Framework 6, and the changelog for the .NET connectior says that 6.8.x added support for MySQL.

I’m out of ideas, hopefully someone can help me with this. Thanks in advance.

2/9/2014 12:02:25 AM

Popular Answer

It seems like you may be using the wrong providerName in your connection string, it should be System.Data.EntityClient.

Here's how I finally got my model-first code to work with MySQL and what my app.config looks like:

  <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;"

In case that doesn't work, here's the entityFramework section. You'll notice the codeConfigurationType attribute I used in the following section. It is adds dependency resolvers for MySQL, but there are other ways of doing it which you can read about in the MySQL: EF 6 Support documentation.

<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
    <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"/>
2/9/2014 11:31:28 AM

Related Questions


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