一、原因
沒有屬性[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