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

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

问题描述

我使用的的Visual Studio 2013 实体框架5 和M ySQL服务器5.7.9



在试图创建数据库模型(或更新模型从数据库的)出现以下消息:



< BLOCKQUOTE>

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




我知道这个问题已经被问过,但我避风港找不到任何解决方案。
我还没有降级到MySQL 5.6的选项。



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



该示例表

  CREATE TABLE NEW_TABLE 

ID INT(11 )NOT NULL AUTO_INCREMENT,
名称VARCHAR(45)NOT NULL,
PRIMARY KEY(ID)

ENGINE = InnoDB的AUTO_INCREMENT = 1默认字符集= UTF8;

如果该表从主键,然后在模型正在创建因为它应该只包含。



编辑:
。如果我让这两个领域的主键被没有任何错误创建的模型



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



亲切的问候。



完整的错误堆栈:




无法生成因为以下异常的模式:
'System.Data.StrongTypingException:值表'TableDetails列
'IsPrimaryKey'是为DBNull。 --->
System.InvalidCastException:指定的转换无效。在
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内,名单 1安培;在$ invalidKeyTypeColumns); excludedColumns,
名单 1安培b $ b Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntityType(IList的 1
柱,布尔和放大器; needsDefiningQuery)在
Microsoft.Data.Entity.Design .VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets在
微软(IEnumerable的 1
tableDetailsRows,EntityRegister entityRegister,IList的
1
entitySetsForReadOnlyEntityTypes,DbObjectType的objectType) .Data.Entity.Design.VersioningFacade.ReverseEngineerDb.StoreModelBuilder.CreateEntitySets在$ b(IEnumerable的 1
tableDetailsRowsForTables,IEnumerable的
1 tableDetailsRowsForViews,
entityRegister entityRegister) $ b 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 b $ b。在
Microsoft.Data.Entity(名单 1
错误) .Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModels(字符串
storeModelNamespace,列表
1的错误)在
Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine。 ModelBuilderEngine.GenerateModel(EdmxHelper
edmxHelper)。从数据库加载元拿了
00:00:00.5856317



解决方案

实体框架(版本6.1.3)和MySQL服务器(5.7)



解决这个问题的方法之一是,

  1。开放服务(services.msc),然后重新启动MySQL57服务。 
2.在MySQL中执行以下命令。
使用<<数据库名称>> ;;
设置全局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)

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天全站免登陆