1. 新建项目
打开VS2010,选择 文件>新建>项目,新建ASP.NET MVC3 Web 应用程序,我这里把它命名为Blog。
![image bubuko.com,布布扣](http://image.mamicode.com/info/201408/20180110154107163855.png)
2. 编写实体类
对于一个博客,一下几个类应该是必须的吧:
- Post 博客文章类
- Comment 文章评论类,和Post是一对多的关系
- Category 目录类,和Post是一对多的关系
- Tag 标签类,和Post是多对多的关系
- FriendLink 友情链接类
先不考虑管理员之类的东西。 在Model中依次添加上面的类。
![image bubuko.com,布布扣](http://image.mamicode.com/info/201408/20180110154107166785.png)
namespace Blog.Models { public class Post { public int ID { get; set; } public int CategoryID { get; set; }
public string Title { get; set; } public string Summary { get; set; } public string Alias { get; set; } public string Content { get; set; } public DateTime CreateTime { get; set; }
public Category Category { get; set; } public ICollection<Tag> Tags { get; set; } public ICollection<Comment> Coments { get; set; } } }
namespace Blog.Models { public class Comment { public int ID { get; set; } public int PostID { get; set; } public int Level { get; set; } public int ReplyTo { get; set; }
public string UserName { get; set; } public string Email { get; set; } public string Website { get; set; } public string Content { get; set; } public DateTime CreateTime { get; set; }
} }
namespace Blog.Models { public class Category { public int ID { get; set; }
public string Name { get; set; } public string Alias { get; set; } public string Description { get; set; } public DateTime CreateTime { get; set; }
public ICollection<Post> Posts { get; set; } } }
namespace Blog.Models { public class Tag { public int ID { get; set; }
public string Name { get; set; } public string Alias { get; set; }