mysql dbnull_c# – MySQL – 实体:表’TableDetails’中的列’IsPrimaryKey’的值是DBNull...

我使用Visual Studio 2013与实体框架5和MySQL服务器5.7.9。

当尝试从数据库创建模型(或“从数据库更新模型”)时,将显示以下消息:

‘System.Data.StrongTypingException: The value for column

‘IsPrimaryKey’ in table ‘TableDetails’ is DBNull . —> System.InvalidCastException: Specified cast is not valid.

我知道这个问题以前被问过,但我没有找到任何解决方案。

我也没有选择降级到MySQL 5.6。

即使对于简单的表也出现问题。

样本表

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;

如果表只包含主键,则会按照原样创建模型。

编辑:

如果我使两个字段PRIMARY键,正在创建模型没有任何错误。

有没有人有这个想法?

亲切的问候。

完整的错误堆栈:

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值