1121_EF模型生成過程中檢測到一個或多個驗證錯誤

一、原因

沒有屬性[Key]。

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

二、解決

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

三、錯誤信息

模型生成過程中檢測到一個或多個驗證錯誤:

EFModel.HL7LabTestNormalReport: : EntityType“HL7LabTestNormalReport”未定義鍵。請為該 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:行號 294
   在 HemoSystemClient.AppDatabase.DoAction(Action`1 action, Boolean showException) 位置 D:\RjyxProgram\HemoSystem\HemoSystemClient\AppDatabase.cs:行號 53
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容