EF6 MySQL StrongTypingException When Column is not PK

前端 未结 4 1433
北恋
北恋 2021-02-08 16:48

We are using MySql and Entity FrameWork with VS 2013 those are the tools installed:

  • MySql Server 5.7.8
  • MySql WorkBench 6.3.
  • MySql for Visual Stud
相关标签:
4条回答
  • 2021-02-08 17:06

    I have pinpointed that this error appears only to connections with 5.7.8 mysql server which is in release candidate state. With the latest stable version 5.6.25 the entity framework works correctly.

    0 讨论(0)
  • 2021-02-08 17:06

    Here is the english version of the error. It also applies for VS2015 and MySQL.Data 6.9.7

        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)'.
    
    0 讨论(0)
  • 2021-02-08 17:17

    Entity Framework (version 6.1.3) and MySQL Server (5.7)

    One way to resolve the issue is,

    1. Open Services (services.msc) and restart MySQL57 service.
    2. Execute the following commands in MySQL.

      use <<database name>> set global optimizer_switch='derived_merge=OFF';

    3. Update the .edmx.

    0 讨论(0)
  • 2021-02-08 17:27

    I had the same problem, I solved it uninstalling mysql server 5.7 x64 and intallig mysql server 5.5 x86.

    I hope it helps

    0 讨论(0)
提交回复
热议问题