Setting my a .net core 2.x class library with ef core 2. Have generated the scaffolding for the entities from my db schema. However, I forgot to even check whether there as an option to pluralize the entity names. I noticed this when I pulled over one my methods from a class library that uses EF 6.1 and the entities are pluralized. Is there an option for this and to simply regenerate my entities as pluralized?
Asked
Active
Viewed 1,707 times
2
-
delete the model files and regenerate again – Vivek Nuna Jun 09 '18 at 07:46
-
See https://stackoverflow.com/questions/39281647/entityframework-core-database-first-approach-pluralizing-table-names – pjs Jun 11 '18 at 11:22
-
Best solution I have found so far: http://anthonygiretti.com/2018/01/12/entity-framework-core-2-pluralization-and-singularization/ – ocuenca Jun 22 '18 at 17:44
1 Answers
1
Write a class that implements the
Microsoft.EntityFrameworkCore.Design.IPluralizerinterface. You can write your own, or use a NuGet package such asInflectorpublic class Pluralizer : IPluralizer { public string Pluralize(string name) { return Inflector.Inflector.Pluralize(name) ?? name; } public string Singularize(string name) { return Inflector.Inflector.Singularize(name) ?? name; } }Write a class that implements the
Microsoft.EntityFrameworkCore.Design.IDesignTimeServicesinterface to register yourIPluralizerimplementation in your entity framework project.public class DesignTimeServices : IDesignTimeServices { public void ConfigureDesignTimeServices(IServiceCollection services) { services.AddSingleton<IPluralizer, Pluralizer>(); } }Run (or rerun) your
Scaffold-DbContextcommand from the package manager console as usual. If you want it to overwrite the previously generated code, you need the-forceoption.
podiluska
- 50,950
- 7
- 98
- 104