我已经开始学习ASP.NET MVC,并且在这个时候学习我想创建简单的博客网站。我决定使用ASP.NET MVC和ORM实体框架。可能你有这个主题的一些有用的链接? 我试着从创建Model代码开始。 我有3班发布,用户(用户可以是管理员),评论。如何使用EF在ASP.NET MVC中自动创建数据库和存储库?
请帮助我建立数据库模型之间的关系。我有这样的代码,现在这一权利:
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创建评论列表还是只写int CommentID?我从来没有用过很深的数据库,只是看了几节课。有人可以建议如何使存储库或更正我的模型代码? 非常感谢!
你有没有看过第一个教程的代码? – 2012-03-15 22:21:25
+1 - 欢迎来到StackOverflow:o) – Andrew 2012-03-15 22:35:13
谢谢你安德鲁! – BeginerDummy 2012-03-15 22:58:28