EntityType 'Breed' has no key defined. Def

2019-07-24 08:05发布

It may looks like a copy of already asked question. i have checked all the solutions but my problem is non-logical.

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

Error Kamdhenu.Models.Breed: : EntityType 'Breed' has no key defined. Define the key for this EntityType. Breeds: EntityType: EntitySet 'Breeds' is based on type 'Breed' that has no keys defined.

1条回答
forever°为你锁心
2楼-- · 2019-07-24 08:22

Define the properties as public. Without specifier they are private by default and EF won't recognize and map private properties:

public int id { get; set; }
public string name { get; set; }
查看更多
登录 后发表回答