EF6 Database-First Approach: Why do I get "System.Data.Entity.ModelConfiguration.ModelValidationException"?

0

I get a Modelvalidation exception in all models claiming the key is not defined. But keys are defined nicely in EDMX file generated with the command "Update Model from Database", and when I check properties the Entity Keys are all defined. The code is in Framework 4.5 with EF 6.0.

System.Data.Entity.ModelConfiguration.ModelValidationException
  HResult=0x80131500
  Message=One or more validation errors were detected during model generation:

GM.EFatura.TBLCAHAR: : EntityType 'TBLCAHAR' has no key defined. Define the key for this EntityType.
GM.EFatura.TBLCASABIT: : EntityType 'TBLCASABIT' has no key defined. Define the key for this EntityType.
...
TBLSTSABITEK: EntityType: EntitySet 'TBLSTSABITEK' is based on type 'TBLSTSABITEK' that has no keys defined.

  Source=EntityFramework
  StackTrace:
   at System.Data.Entity.Core.Metadata.Edm.EdmModel.Validate()

It was never the case before in EF 5.0

Additional Exception information:

This exception was originally thrown at this call stack:
System.Data.Entity.Core.Metadata.Edm.EdmModel.Validate()
System.Data.Entity.DbModelBuilder.Build(System.Data.Entity.Core.Common.DbProviderManifest, System.Data.Entity.Infrastructure.DbProviderInfo)
System.Data.Entity.DbModelBuilder.Build(System.Data.Common.DbConnection)
System.Data.Entity.Internal.LazyInternalContext.CreateModel(System.Data.Entity.Internal.LazyInternalContext)
System.Data.Entity.Internal.RetryLazy<TInput, TResult>.GetValue(TInput)
entity-framework
ef-database-first
asked on Stack Overflow Aug 12, 2020 by HGMamaci • edited Aug 12, 2020 by HGMamaci

1 Answer

0

It seems to be a Visual Studio related bug. When I get this exception, I restart VS and it is good again.

answered on Stack Overflow Jan 13, 2021 by HGMamaci

User contributions licensed under CC BY-SA 3.0