Home > Mobile >  Scaffold-DbContext automatically adds plural "s" / EntityFrameworkCore 6.0.4
Scaffold-DbContext automatically adds plural "s" / EntityFrameworkCore 6.0.4

Time:05-10

I have an existing database and want to use entityframework with the db first approach. I found a lot of people asking how to pluralize their DbSet-property-names in their DbContext class but I do exactly have the opposite problem. When I run Scaffold-DbContext from the package-manager console in vs it creates the database model and automatically adds an "s" to all my DbSet-names (which I dont want).

Does anyone have an idea why this happens or how do I prevent Scaffold-DbContext from doing this?

The full command I'm using is

Scaffold-DbContext -UseDatabaseNames "{constring}" Microsoft.EntityFrameworkCore.SqlServer -OutputDir "Entities" -ContextDir ".\" -Context "MyContext"

CodePudding user response:

If you are using EF Core 5, then you can use the below

To disable the pluralizer, use -NoPluralize switch on Scaffold-DbContext.

This is as per documentation given by Microsoft

  • Related