EF模型生成過程中檢測(cè)到一個(gè)或多個(gè)驗(yàn)證錯(cuò)誤

一、原因

沒有屬性[Key]。

        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int LabTestReportID { get; set; }

二、解決

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int LabTestReportID { get; set; }

三、錯(cuò)誤信息

模型生成過程中檢測(cè)到一個(gè)或多個(gè)驗(yàn)證錯(cuò)誤:

EFModel.HL7LabTestNormalReport: : EntityType“HL7LabTestNormalReport”未定義鍵。請(qǐng)為該 EntityType 定義鍵。
HL7LabTestNormalReport: EntityType: EntitySet“HL7LabTestNormalReport”基于未定義任何鍵的類型“HL7LabTestNormalReport”。


   在 System.Data.Entity.Core.Metadata.Edm.EdmModel.Validate()
   在 System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
   在 System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
   在 System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
   在 System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
   在 System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   在 System.Data.Entity.Internal.LazyInternalContext.get_ObjectContext()
   在 System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery[TElement](String sql, Nullable`1 streaming, Object[] parameters)
   在 System.Data.Entity.Internal.InternalContext.ExecuteSqlQueryAsIEnumerator[TElement](String sql, Nullable`1 streaming, Object[] parameters)
   在 System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(Type elementType, String sql, Nullable`1 streaming, Object[] parameters)
   在 System.Data.Entity.Internal.InternalSqlNonSetQuery.GetEnumerator()
   在 System.Data.Entity.Infrastructure.DbRawSqlQuery`1.GetEnumerator()
   在 System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   在 System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   在 HemoSystemClient.AppDatabase.<>c.<get_AllTableViewNames>b__18_0(AppDbContext db) 位置 D:\RjyxProgram\HemoSystem\HemoSystemClient\AppDatabase.cs:行號(hào) 294
   在 HemoSystemClient.AppDatabase.DoAction(Action`1 action, Boolean showException) 位置 D:\RjyxProgram\HemoSystem\HemoSystemClient\AppDatabase.cs:行號(hào) 53
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容