MySQL - 实体:表'TableDetails'中的列'IsPrimaryKey'的值为DBNull [英] MySQL - Entity : The value for column 'IsPrimaryKey' in table 'TableDetails' is DBNull

查看:136
本文介绍了MySQL - 实体:表'TableDetails'中的列'IsPrimaryKey'的值为DBNull的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Visual Studio 2013 实体框架5 和M ySQL Server 5.7.9



当尝试从数据库(或'从数据库更新模型')创建模型时,会出现以下消息:



< blockquote>

'System.Data.StrongTypingException:表'TableDetails'中的列
'IsPrimaryKey'的值为DBNull。 ---> System.InvalidCastException:指定的转换无效


我知道这个问题以前已经被问过了,但是我还没有找不到任何解决方案。
此外,我没有选择降级到MySQL 5.6。



即使是一个简单的表格也会出现问题。



样本表

  CREATE TABLE new_table 

id int )NOT NULL AUTO_INCREMENT,
name varchar(45)NOT NULL,
PRIMARY KEY(id)

ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8;

如果表仅由主键组成,那么该模型正在被创建。 p>

编辑:
如果我同时创建两个字段PRIMARY键,那么模型正在被创建而没有任何错误。



有没有人对此有任何想法?



请问。



完全错误堆栈:


由于以下异常,无法生成模型:
'System.Data.StrongTypingException:值对于列
'TableDetails'中的'IsPrimaryKey'是DBNull。 --->
System.InvalidCastException:指定的转换无效。 at
Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.TableDetailsRow.get_IsPrimaryKey()
---内部异常堆栈跟踪结束---在Microsoft.Data.Entity.Design.VersioningFacade .ReverseEngineerDb.SchemaDiscovery.TableDetailsRow.get_IsPrimaryKey()

Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateProperties(IList 1
列,IList
1个错误,列表 1& keyColumns,List 1& excludedColumns,
列表 1& invalidKeyTypeColumns) b
$ b Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntityType(IList
1
columns,Boolean& needsDefiningQuery)
Microsoft.Data.Entity.Design .VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets(IEnumerable 1
tableDetailsRows,EntityRegister entityRegister,IList
1
entitySetsForReadOnlyEntityTypes,DbObjectT ype objectType)
Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets(IEnumerable 1
tableDetailsRowsForTables,IEnumerable
1 tableDetailsRowsForViews,
EntityRegister entityRegister)在
Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.Build(StoreSchemaDetails
storeSchemaDetails)
Microsoft.Data.Entity.Design.VisualStudio.ModelWizard .Engine.ModelGenerator.CreateStoreModel()

Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.GenerateModel(List 1
errors)at
Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModels(String
storeModelNamespace,List
1个错误)
Microsoft.Data.Entity .Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModel(EdmxHelper
edmxHelper)'。从数据库加载元数据需要
00:00:00.5856317。



解决方案

实体框架(版本6.1.3)和MySQL服务器(> = 5.7.6)



解决问题的一种方法是,

  1。打开服务(services.msc)并重启MySQL57服务。 
2.在MySQL中执行以下命令。
使用<< database name>> ;;
设置全局optimizer_switch ='derived_merge = OFF';
3.更新.edmx。

这是一个迟到的回复。但希望能帮助某人。



谢谢。


I am using Visual Studio 2013 with Entity Framework 5 and MySQL Server 5.7.9.

When trying to create a Model from the database (or 'Update Model From Database') the following message appears:

'System.Data.StrongTypingException: The value for column 'IsPrimaryKey' in table 'TableDetails' is DBNull . ---> System.InvalidCastException: Specified cast is not valid.

I know that this question has been asked before, but i haven't find any solution. Also i don't have the option of downgrading to MySQL 5.6.

The problem occurs even for a simple table.

The sample table

CREATE TABLE new_table
(
  id int(11) NOT NULL AUTO_INCREMENT,
  name varchar(45) NOT NULL,
  PRIMARY KEY (id)
) 
ENGINE = InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

If the table consists only from the Primary Key then the model is being created as it should.

EDIT: If i make both the fields PRIMARY Keys the model is being created without any errors.

Does anyone have any idea about this?

Kind Regards.

The full error stack:

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(IList1 columns, IList1 errors, List1& keyColumns, List1& excludedColumns, List1& invalidKeyTypeColumns) at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntityType(IList1 columns, Boolean& needsDefiningQuery) at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets(IEnumerable1 tableDetailsRows, EntityRegister entityRegister, IList1 entitySetsForReadOnlyEntityTypes, DbObjectType objectType) at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets(IEnumerable1 tableDetailsRowsForTables, IEnumerable1 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(List1 errors) at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModels(String storeModelNamespace, List1 errors) at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModel(EdmxHelper edmxHelper)'. Loading metadata from the database took 00:00:00.5856317.

解决方案

Entity Framework (version 6.1.3) and MySQL Server (>= 5.7.6)

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.

It's a late reply. But hope it will help somebody.

Thanks.

这篇关于MySQL - 实体:表'TableDetails'中的列'IsPrimaryKey'的值为DBNull的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆