[转]在ASP.NET MVC3中使用EFCodeFirst 1.0

本文转自:http://kb.cnblogs.com/page/97003/

作者: NinoFocus  来源: 博客园  发布时间: 2011-04-12 10:41  阅读: 11971 次  推荐: 11                   原文链接   [收藏]  

  1. 新建项目

  打开VS2010,选择 文件>新建>项目,新建ASP.NET MVC3 Web 应用程序,我这里把它命名为Blog。

image

  2. 编写实体类

  对于一个博客,一下几个类应该是必须的吧:

  • Post                             博客文章类
  • Comment                     文章评论类,和Post是一对多的关系
  • Category                     目录类,和Post是一对多的关系
  • Tag                             标签类,和Post是多对多的关系
  • FriendLink                  友情链接类

  先不考虑管理员之类的东西。 在Model中依次添加上面的类。

image

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

转载于:https://www.cnblogs.com/freeliver54/p/3936469.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值