entity framework - How do I singularize my tables in EF Code First? -
i prefer using singular nouns when naming database tables. in ef code first however, generated tables plural. dbsets pluralized believe ef generating names don't want singularize these names believe more pratical have them plural in code. tried overriding setting no avail.
any ideas? here code , thanks.
myobjectcontext.cs
public class myobjectcontext : dbcontext, idbcontext { public myobjectcontext(string connstring) : base(connstring) { } public dbset<product> products {get;set;} public dbset<category> categories {get;set;} //etc. protected override void onmodelcreating(modelbuilder modelbuilder) { modelbuilder.conventions.remove<pluralizingentitysetnameconvention>(); } }
you've removed wrong convention (pluralizingentitysetnameconvention) purpose. replace onmodelcreating method below , go.
using system.data.entity.modelconfiguration.conventions.edm.db; ... protected override void onmodelcreating(modelbuilder modelbuilder) { modelbuilder.conventions.remove<pluralizingtablenameconvention>(); }
with entity framework 6, on file inherit dbcontext:
using system.data.entity.modelconfiguration.conventions; protected override void onmodelcreating(dbmodelbuilder modelbuilder) { modelbuilder.conventions.remove<pluralizingtablenameconvention>(); }
Comments
Post a Comment