0
votes

I am using Entity Framework Core 3.0 in my app, and since I want to use singularization/pluralization I have added a Design Time Services class:

 public class MyDesignTimeServices : IDesignTimeServices
    {
        public void ConfigureDesignTimeServices(IServiceCollection services)
        {
            services.AddSingleton<IPluralizer, MyPluralizer>();
        }
    }

    public class MyPluralizer : IPluralizer
    {
        public string Pluralize(string name)
        {
            return Inflector.Pluralize(name) ?? name;
        }

        public string Singularize(string name)
        {
            return Inflector.Singularize(name) ?? name;
        }
    }

but when I use Scaffold-DbContext from the Package Manager console as before:

Scaffold-DbContext "Server=localhost;Database=MyDb;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Force

the design time services are not invoked.

How do I scaffold / generate my code and also invoke this?

1

1 Answers

-1
votes

Make sure to run the command at the root of your project:

dotnet ef dbcontext scaffold "Server=localhost;Database=MyDb;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Models -f