Entity Framework 6 and MySQL, model first

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

Question

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=MySql.Data.MySqlClient;
    provider connection string='server=127.0.0.1;
    user id=fire;password=fire_db;
    database=fire_dotnet'" 
  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:

<entityFramework>
    <providers>
        <provider invariantName="MySql.Data.MySqlClient" 
            type="MySql.Data.MySqlClient.MySqlProviderServices, 
            MySql.Data.Entity.EF6, Version=6.8.3.0, 
            Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </providers>
</entityFramework>
<system.data>
<DbProviderFactories>
    <clear />
    <remove invariant="MySql.Data.MySqlClient" />
    <add name="MySql.Data.MySqlClient" 
        invariant="MySql.Data.MySqlClient" 
        description=".Net Framework Data Provider for MySQL" 
        type="MySql.Data.MySqlClient.MySqlClientFactory, 
        MySql.Data, Version=6.8.3.0, Culture=neutral, 
        PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>

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.

1
2
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:

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

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