我已经开始学习ASP.NET MVC,现在我想创建一个简单的博客网站。我决定使用ASP.NET MVC和ORM Entity Framework。也许你有一些关于这个主题的有用链接?
我试图从创建模型代码开始。我有三个类Post、User(用户可以是管理员)、Comments。
请帮我制定数据库模型之间的关系。目前我的代码如下:
我试图从创建模型代码开始。我有三个类Post、User(用户可以是管理员)、Comments。
请帮我制定数据库模型之间的关系。目前我的代码如下:
public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public List<Comment> Comments { get; set; }
public DateTime PublishDate { get; set; }
}
public class User
{
public readonly bool IsAdmin { get; set; }
public string FirstName { get; set; }
public string SecondName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public DateTime DateOfBirthday { get; set; }
public string Country { get; set; }
public string City { get; set; }
public List<Post> Posts { get; set; }
public List<Comment> Comments { get; set; }
}
public class Comment
{
public int CommentId { get; set; }
public string UserName { get; set; }
public string Content { get; set; }
public DateTime PublishDate { get; set; }
}
以下是我创建数据库表的类,但我不确定如何建立多对一等关系。 为帖子(Post)创建评论(Comment),是将评论(Comment)列表(List of Comments)与帖子(Post)关联,还是只需编写评论(Comment)ID(int CommentID)即可?我从未深入使用过数据库,只是看了几节课。请问有人能够建议我如何制作存储库或更正我的模型代码吗? 非常感谢!