EntityType 'Breed' has no key defined. Define the key for this EntityType

亡梦爱人 提交于 2019-12-24 14:18:07

问题


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:


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; }


来源:https://stackoverflow.com/questions/18036392/entitytype-breed-has-no-key-defined-define-the-key-for-this-entitytype

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!