Bug #70758 MySql Connector Targetting wrong namespace for EF6
Submitted: 28 Oct 2013 23:29 Modified: 7 Nov 2013 20:32
Reporter: Travis J Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.7.4 OS:Any
Assigned to: Fernando Gonzalez.Sanchez CPU Architecture:Any
Tags: EF6, entityframework, namespace

[28 Oct 2013 23:29] Travis J
Description:
In Microsoft's infinite wisdom, they have chosen to change namespaces.

"The general rule for namespace changes is that any type in System.Data.* is moved to System.Data.Entity.Core.*. In other words, just insert Entity.Core. after System.Data." -http://msdn.microsoft.com/en-US/data/dn469466

The problem with the change for the MySql Connector is that it is now targeting the wrong namespace (this happened in one of my repositories as well). As a result, this error occurs

The 'Instance' member of the Entity Framework provider type 'MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or later; see http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

I tried version 6.8.0.0 and 6.7.2.2 both with the same result as this. It is easy to see by looking inside of the reference browser,

public sealed class MySqlClientFactory : System.Data.Common.DbProviderFactory 

is shown for the MySql Connector. However, as per the new namespace change (and as indicated in the error shown above) this namespace is incorrect. It should be

public sealed class MySqlClientFactory : System.Data.Entity.Core.Common.DbProviderFactory

I know this seems trivial, but making this one change will fix this connector for use with EF6.

How to repeat:
Add a nuget package for Entity Framework in VS2012. Add the nuget package for MySql. Attempt to query using the connector.

Suggested fix:
Change the namespace target

public sealed class MySqlClientFactory : System.Data.Entity.Core.Common.DbProviderFactory
[1 Nov 2013 18:57] Fernando Gonzalez.Sanchez
Hi,

Thanks for your bug report, currently Connector/NET 6.7.4 supports EF5 (for .NET 4) and EF 4.3 (for .NET 3.5).

There are no plans to support EF 6 on Cnet 6.7.4, but...

We are fully supporting EF 6 in Connector/NET 6.8 (6.8.0 alpha is already out).
[5 Nov 2013 22:38] Travis J
Is 6.8 going to be different than 6.8 alpha? I reproduced this on 6.8 alpha when attempting to use the connector with EF6. Looking at the reference signature for 6.8 alpha shows the provider is still inheriting from the deprecated namespace and as a result causes an exception when any attempt to use the provider is used.
[6 Nov 2013 0:01] Fernando Gonzalez.Sanchez
Hi Travis,

Thanks for your feedback, 

First of all, please note that the packages for Connector/NET available at Nuget are not official (someone from the community is in charge of them, not Oracle).

This is important because the Cnet 6.8 Installer takes care of some important setup steps.

Entity Framework 6 introduced a new way to register new EF providers, the way using DbProviderServices is considered the legacy way.

In Connector/NET 6.8 we are supporting both 
- EF5 (with the legacy way and assembly MySql.Data.Entity.EF5.dll)
- EF6 (with the new way and assembly MySql.Data.Entity.EF6.dll).

For the new way to work in DbFirst for example you need to
- Add EF6 nuget package
- Add a reference to MySql.Data.Entity.EF6.dll
- Modify the app.config to register the MySql provider, like
<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider> 
    </providers>
  </entityFramework>
- Now you add a new edmx model, run the wizard for db first, and will work.
[6 Nov 2013 0:04] Fernando Gonzalez.Sanchez
Travis,

If you need, I can send you by mail a sample project on how to use EF6 with the new configuration method.

Regards.
[7 Nov 2013 20:32] Travis J
Thank you for the correction Fernando! I believe I had incorrectly used the provider definition inside of the config file (I think I omitted the .EF6 suffix in the type attribute). I am able to confirm that the connector is now working for me with EF6.
[26 Nov 2013 9:29] Detlef Martin
Hi!

I have done exactly what you have said. I have installed EF6, Connector 6.8.1, added references to my project and modified app.config. After trying to insert a new Entity Model I get the following message: no provider found for EF6.

It would be nice of you to provide an example project with working EF6 and a working connector.

regards Adam
[26 Nov 2013 17:04] Fernando Gonzalez.Sanchez
Hi,

We are going to produce a tutorial in the blog.

In the meantime I think you are missing compiling the project (rebuild); that will copy to bin/debug (or bin/release) the referenced assemblies EntityFramework.dll and MySql.Data.Entity.EF6.dll together with the updated app.config file, which you changed to register the MySql EF6 provider.

Regards.