简体   繁体   中英

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");

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.

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

@bricelam是 EF Core 团队的成员,他发布了 这篇博文,他建议使用他的Bricelam.EntityFrameworkCore.Pluralizer包,该包基于 EF Core 复数化服务。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM