问题
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