Mvc5+ef6 Development Exercises
Because the database is designed first, you cannot use the "Conventions" of EF in terms of names. Cause a lot of problems.
You need to override the Onmodelcreating method
The code is as follows:
usingSystem;usingSystem.Collections.Generic;usingSystem.Data.Entity;usingSystem.Data.Entity.ModelConfiguration.Conventions;usingSystem.Linq;usingsystem.web;namespacewebapplication2.models{ Public classThcontext:dbcontext {//You can add the custom code to the this file. Changes is not being overwritten. // //If you want the Entity Framework to drop and regenerate your database//automatically whenever the your model schema, use data migrations. //For more information refer to the documentation:// http://msdn.microsoft.com/en-us/data/jj591621.aspx PublicThcontext ():Base("Name=thcontext") { } PublicSystem.data.entity.dbset<webapplication2.models.thenterprise> Th_enterprise {Get;Set; } protected Override voidonmodelcreating (Dbmodelbuilder modelBuilder) {Base. Onmodelcreating (ModelBuilder); ModelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); //MAP schemasModelbuilder.entity<webapplication2.models.thenterprise> (). ToTable ("th_enterprise"); } }}
MVC5 + EF6 Onmodelcreating method modify Dbset name corresponding