Bug #79289 System.Data.StrongTypingException when adding or updating Entity Framework
Submitted: 16 Nov 2015 8:42 Modified: 16 Nov 2015 9:41
Reporter: Peter Hanna Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Visual Studio Integration Severity:S1 (Critical)
Version:MySQL 5.7.9 OS:Microsoft Windows (Windows Server 2012)
Assigned to: CPU Architecture:Any
Tags: ADO.NET, Entity Framework 6, System.Data.StrongTypingException, Visual Studio

[16 Nov 2015 8:42] Peter Hanna
Description:
The following MySQL Products were freshly installed on Windows Server 2012 DB machine:
mysql-installer-community-5.7.9.1

The following MySQL products were freshly installed on Windows 7
Visual Studio 2013 with Update 5
mysql-connector-net-6.9.8.msi
mysql-connector-net-6.8.7.msi (Also Trialled without success)
mysql-for-visualstudio-1.2.5.msi

In Visual studio when attempting to load ADO.Net entity framework Data model from an existing database the following error is encountered.

Unexpected exception occurred when generating the model. See output window for more details. Exception Message: 'StrongTypingException: The value for column 'IsPrimaryKey' in table 'TableDetails' is DBNull.'.

The Error recorded in the Output window in Visual Studio.

Unable to generate the model because of the following exception: 'System.Data.StrongTypingException: The value for column 'IsPrimaryKey' in table 'TableDetails' is DBNull. ---> System.InvalidCastException: Specified cast is not valid.
   at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.TableDetailsRow.get_IsPrimaryKey()
   --- End of inner exception stack trace ---
   at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.TableDetailsRow.get_IsPrimaryKey()
   at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateProperties(IList`1 columns, IList`1 errors, List`1& keyColumns, List`1& excludedColumns, List`1& invalidKeyTypeColumns)
   at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntityType(IList`1 columns, Boolean& needsDefiningQuery)
   at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets(IEnumerable`1 tableDetailsRows, EntityRegister entityRegister, IList`1 entitySetsForReadOnlyEntityTypes, DbObjectType objectType)
   at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets(IEnumerable`1 tableDetailsRowsForTables, IEnumerable`1 tableDetailsRowsForViews, EntityRegister entityRegister)
   at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.Build(StoreSchemaDetails storeSchemaDetails)
   at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.CreateStoreModel()
   at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.GenerateModel(List`1 errors)
   at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModels(String storeModelNamespace, ModelBuilderSettings settings, List`1 errors)
   at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModel(ModelBuilderSettings settings, IVsUtils vsUtils, ModelBuilderEngineHostContext hostContext)'.
Loading metadata from the database took 00:00:00.4447030.
Generating the model took 00:05:24.4807287.

How to repeat:

Create a new visual Studio Project.
Add NuGet Package MySQL.Data Version 6.9.8
Add NuGet Package MySql.Data.Entity 6.9.8
Add NuGet Package MySQL.Data.Entities 6.9.8

In Visual Studio, Right click on the active project-> Add -> New item
Select ADO.NET Entity Data Model
Select "EF Designer from Database"
Add MySQL Connection Details
In The Entity Data Model Wizard Select any table to import.
Pluralize or Singularize generated object names is checked.
Include Foreign key columns in the model unchecked
Import selected stored procedures and functions into the entity model unchecked.
Click Finish
[16 Nov 2015 9:41] Chiranjeevi Battula
Hello  Peter Hanna,

Thank you for the bug report.
This is duplicate of Bug #79163, please see Bug #79163.

Thanks,
Chiranjeevi.
[20 Sep 2016 19:17] Marcio Oliveira
Adicionei ao projeto a referĂȘncia MySql.ConnectorNET.Data 6.8.3.2.
[8 Feb 2017 9:28] Mohamed ARRIOUACH
This fix the bug for me (Visual Studio 2015 Community):

(set global optimizer_switch='derived_merge=off')