EF Core 2.0 中的 EnglishPluralizationService 在哪里?

Where is EnglishPluralizationService in EF Core 2.0?

EF Core 2.0 仍然有其约定,它可以将复数更改为单数,将单数更改回复数。因此它肯定内置了多元化服务。

但我找不到此服务以将其用于其他目的。

在 EF 6 中,我会写:

using System.Data.Entity.Infrastructure.Pluralization;

// Then somewhere in code
var englishPluralizationService = new EnglishPluralizationService();
var singularCat = englishPluralizationService.Singularize("Cats");

EF Core 中没有内置复数,但您可以挂钩例如 Inflector 包:https://www.nuget.org/packages/Inflector/

我在 "EF Core Power Tools" 中这样做 - 请参阅 https://github.com/aspnet/EntityFrameworkCore/commit/dda3f43c046c2464f4813fdbb4261a6146aa4432 了解更多信息

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.

不,它不能那样做,也没有集成的多元化服务。

如文档的 Table Mapping 部分所述,它使用一个简单的约定:

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 引入了 IPluralizer service ,用于在脚手架期间单数化实体类型名称并复数 DbSet 名称,但如 link

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

小矮子,没有这样的服务。对于 "other needs",您必须使用自己的或第 3 方的复数形式。

@bricelam, a member of the EF Core team, has published this blogpost, where he suggests using his Bricelam.EntityFrameworkCore.Pluralizer包,即基于EF Core多元化服务。