Reverse Engineering: Enable pluralization/singularization when scaffolding a model from a database
See original GitHub issueDatabase scaffolding has no pluralization service and the entity models are generated mapping the exact name of database objects. My suggestion is to enable this pluralization through a DI service that could be overridden at the ef
CLI like this:
dnx ef dbcontext scaffold "Server=myserver;Database=Foo;user id=me;password=pwd" EntityFramework.SqlServer --use-pluralization "MyAssembly.PlurarizationService, MyAssembly"
And on Razor templates this could be exposed as:
...
@:namespace @Model.Namespace
@:{
@: public class @PluralizationService.Singularize(Model.EntityType.Name)
@: {
...
I think the default service could be the one shipped with EF6 (System.Data.Entity.Design.PluralizationServices.PluralizationService
)
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:25 (18 by maintainers)
Top Results From Across the Web
Scaffolding (Reverse Engineering) - EF Core
Reverse engineering is the process of scaffolding entity type classes and a DbContext class based on a database schema.
Read more >Scaffolding a Model from a Database Schema
Reverse Engineering is one of the development workflows of EF Core. It involves scaffolding a model ( DbContext and entity types) from a...
Read more >EF Core 1.1 Pluralization in Reverse Engineer - romiller.com
EF Core includes the ability to reverse engineer a model from an existing database – using the Scaffold-DbContext command in Visual Studio, ...
Read more >Entity Framework Core with Existing Database
This reverse engineering command creates entity and context classes (by deriving DbContext ) based on the schema of the existing database. Let's create...
Read more >Generating a model from an existing database
In this approach, you reverse-engineer a model from an existing database, resulting in the generation of an EDMX file that contains the model...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @rowanmiller, in case someone else finds it helpful, I wrapped it in an extension method:
And used it like this:
But I get an error says cannot find the object “Posts”
I checked what EF is trying to execute with
dnx ef migrations script 20160211201857_second -o c:\temp\rename.txt
and pasted it here. EF is using the new name Posts before it was renamed, so that’s a bug.Since it’s a just a test application I created for a lecture I will present in the office next week I don’t mind using
dnx ef database 0
and start all over again. But out of curiosity what should I do if it is a real production application? fiddle with the__EFMigrationsHistory
table?Thank you very much Rowan, I really like what you did with EF 7 and in ASP.NET 5 in general!
@gdoron stick this code at the start of
OnModelCreating
and it will give you what you are after 😄