We have existing code from EF 6 using a database first approach. The database design has been around for awhile. We want to keep name changes minimized so that code that uses the entities does not have to change.
In .net core 2.0.5 Scaffold-DbContext -UseDatabaseNames is not working as noted, but it is supposed to be restored in .net core 2.1.:
https://github.com/aspnet/EntityFrameworkCore/issues/9146
I want to know if class names will be generated that are singular i.e. if the table is named Forks will the class be named Fork. Will the DbSet names in the generated context use the names of the tables?
Will the column names be left alone?
UseDatabaseNames switch tells EF to use database names instead of PascalCasing them. This was done for tables in 2.0 release. (without PMC switch). In 2.1-preview1-final we added switch on Scaffold-DbContext command. Also we missed out retaining names for column names which was fixed in https://github.com/aspnet/EntityFrameworkCore/issues/9820 in 2.1.0-preview1 release.
Converting Forks to Fork is task of pluralizer service. With alone above switch, if table name is Forks we will use Forks as entity type name. You can register service implementing IPluralizer in your service provider and we will use that to convert to & from. So if service you added says, Forks should be singularized into Fork we'll do so.
Yes, the column names will be left alone
Here is a good example of using IPlualizer.
I love the work the person put into the answer but I would prefer the simplicity of having it built into the tool.
Oh, that reminds me. I need to publish my package. After I do, you can just...
Install-Package Bricelam.EntityFrameworkCore.Pluralizer -IncludePrerelease
Scaffold-DbContext ...
...and you'll get pluralization.
@bricelam Thanks. that worked a treat.
Oh, that reminds me. I need to publish my package. After I do, you can just...
Install-Package Bricelam.EntityFrameworkCore.Pluralizer -IncludePrerelease Scaffold-DbContext ......and you'll get pluralization.
THANK YOU!
@bricelam Thank you!!! That was JUST what I needed.
@bricelam +1.
It works for .NET Core 3.0 apps.
Most helpful comment
Oh, that reminds me. I need to publish my package. After I do, you can just...
...and you'll get pluralization.