Mvc5+ef6+automapper+bootstrap Build Online Blog (1.1)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.