Entity Framework Core 3.0 - scaffold with design time services

asp.net-core c# entity-framework-core

Question

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
0
1/23/2020 11:33:49 AM

Popular Answer

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

0
1/23/2020 2:00:19 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow