{"Multiple identity columns specified for table 'Article'. Only one identity column per table is allowed."}[ComplexType]不可以包含主鍵
在Code First中,倘若被標記[ComplexType]的model類別包含主鍵,在從無到有建立一個資料庫的過程中,將會出現下列錯誤訊息:
{"Multiple identity columns specified for table 'Article'. Only one identity column per table is allowed."}
倘若保留OpenGraph的主鍵,然後將另外一個命名為Article的model類別(也就是持有參考屬性OpenGraph的類別)的主鍵移除,將會出現下列錯誤訊息:
{"One or more validation errors were detected during model generation:\r\n\r\n\\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'Article' has no key defined. Define the key for this EntityType.\r\n\\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'Articles' is based on type 'Article' that has no keys defined.\r\n"}
結論:
標記為[ComplexType]的model類別不可以擁有主鍵。