【发布时间】:2018-02-24 09:54:40
【问题描述】:
在底部错误详细信息中,编码和其他提到的实体都不是我项目的一部分。我仍然得到这个错误。当我在几个小时后启动项目而没有更改时突然生成此错误。 在进行第一次基于实体框架的调用时会发生此错误。
One or more validation errors were detected during model generation:
Website1.Models.Encoding: : EntityType 'Encoding' has no key defined. Define the key for this EntityType.
ActionResults: : The referenced EntitySet 'ActionResults' for End 'ContentResult_ContentEncoding_Source' could not be found in the containing EntityContainer.
ActionResults: : The referenced EntitySet 'ActionResults' for End 'JsonResult_ContentEncoding_Source' could not be found in the containing EntityContainer.
Encodings: EntityType: EntitySet 'Encodings' is based on type 'Encoding' that has no keys defined.
ActionResults: EntityType: EntitySet 'ActionResults' is based on type 'ActionResult' that has no keys defined.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:
Website1.Models.Encoding: : EntityType 'Encoding' has no key defined. Define the key for this EntityType.
ActionResults: : The referenced EntitySet 'ActionResults' for End 'ContentResult_ContentEncoding_Source' could not be found in the containing EntityContainer.
ActionResults: : The referenced EntitySet 'ActionResults' for End 'JsonResult_ContentEncoding_Source' could not be found in the containing EntityContainer.
Encodings: EntityType: EntitySet 'Encodings' is based on type 'Encoding' that has no keys defined.
ActionResults: EntityType: EntitySet 'ActionResults' is based on type 'ActionResult' that has no keys defined.
这里是完整的:数据库类:> HERE
【问题讨论】:
-
您似乎忘记为所需的表列 ID 放置
KeyAttribute。检查它们是否正确插入到数据模型中。 -
我划了两次检查,每个实体都有关键属性。以下不是我的实体
-
能否提供相关的模型类抛出错误?以及您使用相应的模型类尝试了什么?
-
here at this link foreigntutor.com/test.txt,上面也提到了
标签: c# asp.net asp.net-mvc visual-studio entity-framework