首页 > 代码库 > MVC5+EF6+AutoMapper+Bootstrap打造在线博客(1.1)
MVC5+EF6+AutoMapper+Bootstrap打造在线博客(1.1)
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)