Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is EnglishPluralizationService in EF Core 2.0?

EF Core 2.0 still has its conventions and it can change plural to singular and singular back to plural. Thus it definitely has the pluralization service built into it.

Yet I can't find this service to use it for other purposes.

In EF 6, I would write:

using System.Data.Entity.Infrastructure.Pluralization;

// Then somewhere in code
var englishPluralizationService = new EnglishPluralizationService();
var singularCat = englishPluralizationService.Singularize("Cats");
like image 319
mohammad rostami siahgeli Avatar asked Dec 14 '22 19:12

mohammad rostami siahgeli


2 Answers

EF Core 2.0 still has its conventions and it can change plural to singular and singular back to plural. Thus it definitely has the pluralization service built into it.

No, it can't do that and has no integrated pluralization service.

As explained in Table Mapping section of the documentation, it uses a simple convention:

By convention, each entity will be setup to map to a table with the same name as the DbSet<TEntity> property that exposes the entity on the derived context. If no DbSet<TEntity> is included for the given entity, the class name is used.

EF Core 2.0 introduced IPluralizer service that is used to singularize entity type names and pluralize DbSet names during scaffolding, but as stated in the link

this is just a hook where folks can easily plug in their own pluralizer

Shorty, there is no such service. For "other needs" you have to use your own or 3rd party pluralizer.

like image 73
Ivan Stoev Avatar answered Dec 24 '22 18:12

Ivan Stoev


There is no built in pluralization in EF Core, but you can hook in for example the Inflector package: https://www.nuget.org/packages/Inflector/

I do that in "EF Core Power Tools" - see https://github.com/aspnet/EntityFrameworkCore/commit/dda3f43c046c2464f4813fdbb4261a6146aa4432 for more info

like image 38
ErikEJ Avatar answered Dec 24 '22 18:12

ErikEJ