[英]EntityType has no key defined. Define the key for this EntityType
[英]EntityType 'posts' has no key defined. Define the key for this EntityType
我的模特班是
public class posts
{
[Key]
public int AuthorId;
public string author_first_name;
public string author_last_name;
public string post_text;
}
我不明白为什么这么说。 即使我遵循命名约定并且仍然插入了用于安全措施的键注释,它仍然给我错误。
使用EntityFramework声明实体时,请使用属性,而不是字段。
你应该有:
public class Post
{
[Key]
public int AuthorId { get; set; }
public string AuthorFirstName { get; set; }
public string AuthorLastName { get; set; }
public string PostText { get; set; }
}
使用这些数据注释声明属性时,它们必须出现在公共获取器上。
旋转一下,看看是否适合您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.