MVC5+EF6+AutoMapper+Bootstrap打造線上部落格(1.1)

來源:互聯網
上載者:User

標籤:boot   ted   com   cte   str   img   blog   prot   代碼下載   

DAL層的三個Model類:

字典表:CFDict

使用者表:CFUser

使用者愛好表:CFUserHobby(關聯cfuser表和cfdict表)

CFUser表和CFUserHobby表是一對多關聯性,一個使用者有多個愛好,CFDict表和CFUserHobby表是一對多關聯性,某一個愛好可能很多人都有

 

public class CFDict
{
//識別欄位
public int Id { get; set; }

//名稱
public string Name { get; set; }

//父ID
public int ParentId { get; set; }

//所在層,從0開始
public int Level { get; set; }

//所屬分類
public string Category { get; set; }

//排序號
public int? OrderNum { get; set; }

public virtual ICollection<CFUserHobby> CFUserHobbys { get; set; }
}

 

public class CFUser
{
public int Id { get; set; }

//使用者名稱
[StringLength(50)]
public string UserName { get; set; }

//密碼
[StringLength(50)]
public string UserPwd { get; set; }

//郵箱
[StringLength(50)]
public string UserMail { get; set; }

//全名
[StringLength(50)]
public string FullName { get; set; }

//性別
public int? Sex { get; set; }

//出生日期
public DateTime? BirthDay { get; set; }

//城市code
public int? CityCode { get; set; }

//愛好code
public int? HobbyCode { get; set; }

//部落格網站
public int? BlogCode { get; set; }

//部落格名稱
public string BlogName { get; set; }

//註冊日期
public DateTime SignDate { get; set; }

public virtual ICollection<CFUserHobby> CFUserHobbys { get; set; }
}

 

public class CFUserHobby
{
//識別欄位
public int Id { get; set; }

//使用者ID
public int CFUserId { get; set; }

//愛好ID
public int CFDictId { get; set; }

public virtual CFUser CFUser { get; set; }

public virtual CFDict CFDict { get; set; }
}

 

public class CFContext : DbContext
{
public CFContext()
: base("CFContext")
{
}

public DbSet<CFUser> CFUsers { get; set; }

public DbSet<CFDict> CFDicts { get; set; }

public DbSet<CFUserHobby> CFUserHobbys { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

base.OnModelCreating(modelBuilder);
}
}

 

可以看到產生的外鍵:

 原始碼下載QQ群:389496325

MVC5+EF6+AutoMapper+Bootstrap打造線上部落格(1.1)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.