標籤: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)