Skip to content

bricelam/EFCore.Pluralizer

Repository files navigation

Bricelam.EntityFrameworkCore.Pluralizer

latest version downloads license

This project is a working sample that adds design-time pluralization to Entity Framework Core.

Usage

To use the package, simply install it. The pluralizer will be used when reverse engineering a model from an existing database.

Console:

dotnet add package Bricelam.EntityFrameworkCore.Pluralizer
dotnet ef dbcontext scaffold "Data Source=chinook.db" Microsoft.EntityFrameworkCore.Sqlite

PMC:

Install-Package Bricelam.EntityFrameworkCore.Pluralizer
Scaffold-DbContext 'Data Source=chinook.db' Microsoft.EntityFrameworkCore.Sqlite

How it works

On install, the package adds an assembly-level attribute to the project:

[assembly: DesignTimeServicesReference(
    "Bricelam.EntityFrameworkCore.Design.EFCorePluralizerServices, Bricelam.EntityFrameworkCore.Pluralizer")]

This attribute points to a class that registers the IPluralizer service.

class EFCorePluralizerServices : IDesignTimeServices
{
    public void ConfigureDesignTimeServices(IServiceCollection services)
        => services.AddSingleton<IPluralizer, Pluralizer>();
}

At design time, EF Core will find the assembly-level attribute and call the ConfigureDesignTimeServies method to register additional services.