ASP. NET MVC4 music store. The Entity Framework 4.1 table name is automatically converted into a plural number.

Source: Internet
Author: User
In the example of ASP. NET MVC3 Music Store,

 

EntityFramework4.1 The following table names are automatically converted to the plural:

Solution:

 

 

Using System; using System. Collections. Generic;
Using System. Data. Entity;
Using ContosoUniversity. Models;
Using System. Data. Entity. ModelConfiguration. Conventions;
Namespace ContosoUniversity. Models
{
Public class SchoolContext: DbContext
{
Public DbSet <Student> Students {get; set ;}
Public DbSet <Enrollment> Enrollments {get; set ;}
Public DbSet <Course> Courses {get; set ;}
Protected override void OnModelCreating (DbModelBuilder modelBuilder)
{

ModelBuilder. Conventions. Remove <PluralizingTableNameConvention> ();

}

}

}

 

 

The Code creates a DbSet attribute for each object set. In Entity Framework technology, an Entity set is consistent with the table in the database, and an Entity is consistent with the row in the table.

The statement in the OnModelCreating method prevents the table name from being limited to the plural. If you do not do this, the name of the generated table will be named Students,Courses, AndEnrollmentsTo replace Student,Course, AndEnrollment,This is because the developer has not reached an agreement regarding whether the table name uses the plural. This tutorial uses the singular form, but the focus is on which form you can choose to use for naming.

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.