Bug #74388 MySQL Visual Studio Integration
Submitted: 14 Oct 2014 23:16 Modified: 17 Dec 2015 19:13
Reporter: Peter Hanna Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Visual Studio Integration Severity:S3 (Non-critical)
Version:5.6.19 Community Server, 5.6.21 OS:Windows
Assigned to: Luis Penunuri CPU Architecture:Any
Tags: entity framework, Generate model from database fails, Visual Studio

[14 Oct 2014 23:16] Peter Hanna
Description:
O/S (Visual Studio) Windows 7
Visual Studio 12.0.30626 Update 3RC
O/S (Database) Windows Server 2012
MySQL Version 5.6.19

Components referenced in Visual Studio (NuGet Packages)
Entity Framework Version 5.0.2. I upgraded to 6.1.1 and this made no difference
MySql.ConnectorNET.Entity 6.8.3.2
MySQL.Data 6.8.3 Upgraded to 6.9.3 No Difference
mySql.Data.Entities 6.8.3.0

How to repeat:
In visual studio click on an existing Entity Framework Model .edmx file.
Right Click anywhere in the model.
Click on "Generate Database from Model"

Visual Studio will report

Encountered the following errors while processing the template
'C:\Program Files (x86)\Microsoft\Entity Framework Tools\DDGen\SSDLToSQL10.tt:
Line 56, Column 0: 'Running transformation:
System.InvalidOperationException: The SSDL generated by the activity called 'CsdlToSsdlAndMslActivity' is not valid and has the following errors:
No Entity Framework provider found for the ADO.NET provider with invariant name 'MySQL.Data.MySqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.mircosoft.com/fwlink/?LinkId=260882 for more information. at

Microsoft.Data.Entity.Design.DatabaseGeneration.EdmExtension.CreateAndValidatieStoreItemCollection(String ssdl, Version targetFrameworkVersion, IDbDependencyResolver resolver, Boolean catchThrowNamingConflicts)

Note:
I have the following providers in my App.config file
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>

Suggested fix:
If I knew I would have tried it already.
[18 Dec 2014 8:58] Chiranjeevi Battula
Hello Peter Hanna,

Thank you for the bug report.
Verified this behavior on Visual Studio 2013 (VB.Net) with  MySQL Connector/Net 6.9.5.

Thanks,
Chiranjeevi.
[18 Dec 2014 8:59] Chiranjeevi Battula
Error Message screenshot

Attachment: error message.PNG (image/png, text), 125.33 KiB.

[18 Dec 2014 17:13] Fernando Gonzalez.Sanchez
Hi Peter,

From the bug report, it seems you are using the .tt template for MSSQL (SSDLToSQL10), please select from the combobox (in the properties of the edmx diagram, the template for MySQL (must appear as option after the M4VS (MySql For Visual Studio) was installed).

Also, from the docs http://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html, I would like to notice the steps:
1. You need to add a reference to the project for assembly MySql.Data.Entity.EF6.dll 
2. You need to rebuild the solution, so the assembly added in the last step appears in the output folder (bin/debug or bin/release) where the EF designer will look for it.

that should make the trick

Also EF6 is only supported in VS2013 which you are already using

Thanks.
[18 Dec 2014 22:45] Peter Hanna
I changed the DDL Generation Template to SSDLToMySQL.tt (VS) as per your advice.
Cleaned the solution and attempted to rebuild.

I am now getting the error:

Encountered the following erros while processing the template 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen\SSDLToMySQL.tt:
Line 92, Column 0: 'Running transformation: System.NullReferenceException: Object reference not set to an instance of an object at
Microsoft.Data.Entity.Design.DatabaseGeneration.MetadataWorkspaceExtensions.GetAllAssociationsSets(ItemCollection itemCollection) at
Microsoft.VisualStudio.TextTemplating ...........GeneratedTextTransformation.TransformText() in c:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen\SSDLToMySQL.tt:line 93

I have attached a screenshot of the error.
[18 Dec 2014 22:45] Peter Hanna
VS Generate Database from Model Error

Attachment: vs_generate_database_from_model_error.png (image/png, text), 22.25 KiB.

[18 Dec 2014 22:46] Peter Hanna
EF6 Reference added. Error Still occurring.

Attachment: vs_referencesMySql.Data.Entity.EF6.png (image/png, text), 4.76 KiB.

[19 Dec 2014 18:55] Francisco Alberto Tirado Zavala
Hello Peter.

Can you try the same but installing Connector/Net using the Installer rather than installing it from Nuget? (http://dev.mysql.com/downloads/connector/net/) 

I think that the problem could be because when you install connector from Nuget it is not added to the GAC, but VS is trying to load it from there.

Can you test it in that way to be sure of this?

Thanks for your time
[21 Dec 2014 22:28] Peter Hanna
Hi Francisco,

Thanks for your help.

I have noticed in the past that the Nuget packages don't work/deploy as well as when I manually install the .Net Connector and add the reference in Visual Studio.
In fact I think I was forced to install the .Net Connector because the Nuget packages were not working/linking correctly when running my code and the only way I found to fix this was to install the .Net Connector and add the Entity Framework dll reference in visual studio.

I have installed mysql-connector-net-6.9.5.msi

Unfortunately its generating the same error.
[23 Dec 2014 14:57] Francisco Alberto Tirado Zavala
Hello Peter.

I appreciate your confirmation, I'll start some tests to verify the bug and do the fix.

Thanks for your time.
[28 Apr 2015 3:41] Silvio Marques Ferreira
Hi Francisco Alberto Tirado Zavala, how are you?

Do you solved this bug, really was a bug?
I'm getting the same error using conector 6.9.6 and plugin version 1.2.3 with VS 2013.

Thanks in advance!
[26 Nov 2015 17:34] Luis Penunuri
Hi Silvio Marques Ferreira Dirty,

This bug was verified and it's already fixed. It will be released in version 1.2.6.

Thank you, and have a good day !

Regards.
Alfonso Penunuri.
[17 Dec 2015 19:13] Philip Olson
Fixed as of the upcoming MySQL for Visual Studio 1.2.6 release, and here's the changelog entry:

Executing Generate Database from Model from an existing Entity Framework
model would throw an exception related to an error with the T4 template
file, when then aborted the creation of the database. The Connector/Net
Entity Framework assembly (MySql.Data.Entity.EF6.dll) path was fixed in
the MySQL T4 template file (SSDLToMySQL.tt).

Thank you for the bug report.