【发布时间】:2012-04-01 12:14:16
【问题描述】:
我已经开始学习 ASP.NET MVC,在学习的这段时间我想创建一个简单的博客网站。我决定使用 ASP.NET MVC 和 ORM 实体框架。可能你有一些关于这个主题的有用链接? 我尝试先从创建模型代码开始。 我有 3 个类 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; }
}
这些是我创建数据库表的类,但我不确定如何建立多对一的关系。 为帖子制作评论列表还是只写 int CommentID 是否正确?我从来没有深入使用过数据库,只是看了几节课。有人可以建议如何制作存储库或更正我的模型代码吗? 非常感谢!
【问题讨论】:
-
你读过代码优先教程吗?
-
+1 - 欢迎来到 StackOverflow :o)
标签: c# asp.net asp.net-mvc database entity-framework