MVC5 + EF6 + AutoMapper + Bootstrap create an online blog (1.1) and mvc5ef6

Source: Internet
Author: User

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

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.