我的模型课是
public class posts
{
[Key]
public int AuthorId;
public string author_first_name;
public string author_last_name;
public string post_text;
}
我不明白为什么这么说。即使我遵循命名约定并且仍然插入了关键注释以进行安全测量,它仍然给我错误。
我的模型课是
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; }
}
当您使用这些数据注释声明属性时,它们必须出现在公共 getter 上。
试一试,看看它是否适合你。