[英]EntityType 'posts' has no key defined. Define the key for this EntityType
My model class is 我的模特班是
public class posts
{
[Key]
public int AuthorId;
public string author_first_name;
public string author_last_name;
public string post_text;
}
I don't understand why it is saying that. 我不明白为什么这么说。 Even though i am following the naming conventions and still have inserted the key annotation for safe measure it is still giving me the error.
即使我遵循命名约定并且仍然插入了用于安全措施的键注释,它仍然给我错误。
Please use Properties, not fields when declaring Entities using EntityFramework. 使用EntityFramework声明实体时,请使用属性,而不是字段。
You should have: 你应该有:
public class Post
{
[Key]
public int AuthorId { get; set; }
public string AuthorFirstName { get; set; }
public string AuthorLastName { get; set; }
public string PostText { get; set; }
}
When you declare attributes using these Data Annotations they must appear on a public getter. 使用这些数据注释声明属性时,它们必须出现在公共获取器上。
Give this a whirl and see if it works out for you. 旋转一下,看看是否适合您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.