【问题标题】:EntityType 'Breed' has no key defined. Define the key for this EntityTypeEntityType 'Breed' 没有定义键。定义此 EntityType 的键
【发布时间】:2013-08-04 21:00:07
【问题描述】:

它可能看起来像是已提出问题的副本。 我已经检查了所有的解决方案,但我的问题是不合逻辑的。

public class Breed
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    int id { get; set; }
    string name { get; set; }
}

错误 Kamdhenu.Models.Breed: : EntityType 'Breed' 没有定义键。定义此 EntityType 的键。 Breeds:EntityType:EntitySet 'Breeds' 基于没有定义键的类型 'Breed'。

【问题讨论】:

    标签: asp.net-mvc entity-framework-5


    【解决方案1】:

    将属性定义为public。如果没有说明符,默认情况下它们是 private,EF 不会识别和映射私有属性:

    public int id { get; set; }
    public string name { get; set; }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-02
      • 2016-03-16
      • 2012-12-10
      • 2016-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多