我们在VS 2013中使用MySql和Entity FrameWork,这些是安装的工具:
我们已将必要的库导入项目MySQLWeb,MySQL.Data,Mysql.Data.Emtity.EF6
我们使用MySQLWorkBench创建了一个模式,其中包含一个简单的表:
CREATE TABLE `persona` (
`idpersona` int(11) NOT NULL,
`nombre` int(11) DEFAULT NULL,
PRIMARY KEY (`idpersona`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
我们遇到的问题是,我们创建了ADO.net实体数据模型,我们将其连接到数据库,但之后它不会创建模型并显示以下错误:
'System.Data.StrongTypingException:El valor de la columna 'IsPrimaryKey'de la tabla'TableDetails'es DBNull。 ---> System.InvalidCastException:Lacontraiónespecificadanoesválida。 恩 Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.TableDetailsRow.get_IsPrimaryKey() --- Fin del seguimiento de la pila delaexcepcióninterna--- en Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.TableDetailsRow.get_IsPrimaryKey() 恩 Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateProperties(IList
1 columns, IList
1个错误,列出1& keyColumns, List
1& excludedColumns, 列表1& invalidKeyTypeColumns) en Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntityType(IList
1 列,布尔& needsDefiningQuery)en Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets(IEnumerable的1 tableDetailsRows, EntityRegister entityRegister, IList
1 entitySetsForReadOnlyEntityTypes,DbObjectType objectType)en Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets(IEnumerable1 tableDetailsRowsForTables, IEnumerable
1 tableDetailsRowsForViews, EntityRegister entityRegister)en Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.Build(StoreSchemaDetails storeSchemaDetails)en Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.CreateStoreModel() 恩 Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.GenerateModel(列出1 errors) en Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModels(String storeModelNamespace, ModelBuilderSettings settings, List
1个错误)
恩 Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModel(ModelBuilderSettings 设置,IVsUtils vsUtils,ModelBuilderEngineHostContext hostContext)”。 La carga de los metadatos desde la base dedatosardó 00:00:00.4029113。 Lageneracióndelmodeloardó00:03:36.0692240。
我们已经证明,如果我们将所有单列作为主键一切正常,则当一列不是主键时会出现问题它与列的类型无关。
我没有在互联网上找到任何有同样问题的人。
非常感谢您阅读我的问题
问候
答案 0 :(得分:12)
实体框架(版本6.1.3)和MySQL服务器(5.7)
解决问题的一种方法是,
在MySQL中执行以下命令。
use <<database name>>
set global optimizer_switch='derived_merge=OFF';
更新.edmx。
答案 1 :(得分:4)
我已经确定此错误仅出现在5.7.8 mysql服务器的连接中,该服务器处于候选发布状态。使用最新的稳定版本5.6.25,实体框架可以正常工作。
答案 2 :(得分:2)
以下是错误的英文版本。它也适用于VS2015和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)'.
答案 3 :(得分:2)
我遇到了同样的问题,我解决了它卸载mysql server 5.7 x64和intallig mysql server 5.5 x86。
我希望它有所帮助