色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

在ASP.NET MVC3中使用EFCodeFirst 1.0

  1. 新建項目

  打開VS2010,選擇 文件>新建>項目,新建ASP.NET MVC3 Web 應(yīng)用程序,我這里把它命名為Blog。

image

  2. 編寫實體類

  對于一個博客,一下幾個類應(yīng)該是必須的吧:

  • Post                             博客文章類
  • Comment                     文章評論類,和Post是一對多的關(guān)系
  • Category                     目錄類,和Post是一對多的關(guān)系
  • Tag                             標(biāo)簽類,和Post是多對多的關(guān)系
  • 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; set; }
public DateTime CreateTime { get; set; }

public ICollection<Post> Posts { get; set; }
}
}

namespace Blog.Models
{
public class FriendLink
{
public int ID { get; set; }

public string Name { get; set; }
public string URL { get; set; }
public string Description { get; set; }
public DateTime CreateTime { get; set; }
}
}

NET技術(shù)在ASP.NET MVC3中使用EFCodeFirst 1.0,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 阿鲁科尔沁旗| 高碑店市| 郁南县| 青河县| 山阴县| 宁德市| 凌云县| 砚山县| 濮阳县| 陇西县| 花垣县| 章丘市| 西乌珠穆沁旗| 安阳县| 秭归县| 十堰市| 长宁区| 鄄城县| 靖边县| 古交市| 五大连池市| 浦东新区| 新巴尔虎左旗| 攀枝花市| 巴南区| 津市市| 忻城县| 柯坪县| 英山县| 明水县| 高雄市| 临夏市| 永修县| 略阳县| 泉州市| 重庆市| 疏附县| 钟祥市| 岳普湖县| 永和县| 招远市|