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.