The three model classes of the DAL layer:
Dictionary table: cfdict
User table: Cfuser
User Preferences table: Cfuserhobby (associated cfuser tables and cfdict tables)
Cfuser table and Cfuserhobby table is a one-to-many relationship, a user has multiple hobbies, cfdict table and Cfuserhobby table is a a-to-many relationship, a hobby may be a lot of people have
public class Cfdict
{
Identity 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 of Belong
public string Category {get; set;}
Sort number
public int? Ordernum {get; set;}
Public virtual icollection<cfuserhobby> 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;}
Mailbox
[Stringlength (50)]
public string Usermail {get; set;}
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 site
public int? Blogcode {get; set;}
Blog name
public string Blogname {get; set;}
Registration date
Public DateTime signdate {get; set;}
Public virtual icollection<cfuserhobby> Cfuserhobbys {get; set;}
}
public class Cfuserhobby
{
Identity column
public int Id {get; set;}
User ID
public int Cfuserid {get; set;}
Hobby 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);
}
}
You can see the generated foreign key:
Source code Download QQ Group: 389496325
Mvc5+ef6+automapper+bootstrap Build Online Blog (1.1)