天天看點

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.