【问题标题】:Entity Framework generating error for entity that does not exist实体框架为不存在的实体生成错误
【发布时间】: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


【解决方案1】:

问题在于不支持的表列之一的数据类型。列本身就是实体,我不知道如何。

我错误地定义了以下数据类型:

public ActionResult effectcolumn {get; set;}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多