MVC5 + EF6 + AutoMapper + Bootstrap create an online blog (1.1) and mvc5ef6
Three Model classes at the DAL layer:
Dictionary table: CFDict
User table: CFUser
User hobby table: cfuserholobby (associated cfuser table and cfdict table)
The CFUser table and the cfuserhober table are one-to-multiple relationships. A single user has multiple interests. The CFDict table and the cfuserhober table have one-to-many relationships. A certain hobby may have many
Public class CFDict
{
// ID column
Public int Id {get; set ;}
// Name
Public string Name {get; set ;}
// Parent ID
Public int ParentId {get; set ;}
// Layer, starting from 0
Public int Level {get; set ;}
// Category
Public string Category {get; set ;}
// Order Number
Public int? OrderNum {get; set ;}
Public virtual ICollection <cfuserholobby> CFUserHobbys {get; set ;}
}
Public class CFUser
{
Public int Id {get; set ;}
// User Name
[StringLength (50)]
Public string UserName {get; set ;}
// Password
[StringLength (50)]
Public string UserPwd {get; set ;}
// Email
[StringLength (50)]
Public string UserMail {get; set ;}
// Full name
[StringLength (50)]
Public string FullName {get; set ;}
// Gender
Public int? Sex {get; set ;}
// Date of birth
Public DateTime? BirthDay {get; set ;}
// City code
Public int? CityCode {get; set ;}
// Hobby code
Public int? HobbyCode {get; set ;}
// Blog website
Public int? BlogCode {get; set ;}
// Blog name
Public string BlogName {get; set ;}
// Registration Date
Public DateTime SignDate {get; set ;}
Public virtual ICollection <cfuserholobby> CFUserHobbys {get; set ;}
}
Public class cfuserholobby
{
// ID column
Public int Id {get; set ;}
// User ID
Public int CFUserId {get; set ;}
// Hobby ID
Public int CFDictId {get; set ;}
Public virtual CFUser {get; set ;}
Public virtual 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 <cfuserholobby> CFUserHobbys {get; set ;}
Protected override void OnModelCreating (DbModelBuilder modelBuilder)
{
ModelBuilder. Conventions. Remove <PluralizingTableNameConvention> ();
Base. OnModelCreating (modelBuilder );
}
}
The generated foreign key is displayed:
Source code download QQ: 389496325