实体
public class Region
{
[Key]
public int ID;
public string Name;
public string Description;
}
模型
public class RegionModel
{ [Key]
public int ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
错误
System.Data.Edm.EdmEntityType: : EntityType 'Region' has no key defined. Define the key for this EntityType.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet �Regions� is based on type �Region� that has no keys defined.
最佳答案
您的类字段需要更改为属性,以便 EF 正确使用该类;
public class Region
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
关于asp.net-mvc - EntityType 没有定义键。 [Key] 出示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13901065/