Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database-first scaffolding generates entity names ignoring original casing #10678

Closed
ghost opened this issue Jan 10, 2018 · 5 comments
Closed

Comments

@ghost
Copy link

ghost commented Jan 10, 2018

I have an existing EF6 code base, and I'm trying to port that to EF Core. I'm using the following command to scaffold the entity classes from my database

Scaffold-DbContext "MyConnectionString" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

It does generate the DbContext and the necessary entities. But things have changed a lot from EF6 including the naming conventions - how to name entities, properties & navigation (the newly created entities are very different from what I had with my EF6 code).

One of the changes is - Now EF does not singularize class names from table name. e.g. if table name is 'Accessories', earlier entity class used to be 'Accessory', now it is 'Accessories'! This I've fixed using the IPluralizer interface.

BUT, the final entity classes created by EF Core, have names that ignores the original casing! See the following Table-Name that I have in my existing database & the Entity-Name that is generated by EF.

Students >> Students
StudentScores >> StudentScores
XMLDetails >> Xmldetails (this is the problem)

This is different form EF6 behaviour and it also reduces readability of code and developer's productivity (apart from the fact, I'm having to manually change my existing code all over which I'm trying to port).

There are related issues 9257 and 9477 but they deal with the use case - when there are two tables in DB2 with same name but different casing.

The problem seems to come from the way EF code does PascalCase-ing of the names

//namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
//class CandidateNamingService
//method GenerateCandidateIdentifier(string originalIdentifier)
...isFirstCharacterInWord & other logic
candidateStringBuilder.Append(isFirstCharacterInWord ? char.ToUpperInvariant(c) : char.ToLowerInvariant(c));

Further technical details

EF Core version: 2.0.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 8.1
IDE: Visual Studio Community 2017 v15.5.2

@ErikEJ
Copy link
Contributor

ErikEJ commented Jan 10, 2018

This is a duplicate/known issue, fixed in 2.1
My "EF Core Power Tools" can help you with some of your issues, and I can work with you to fix any remaining issues

@ghost
Copy link
Author

ghost commented Jan 10, 2018

@ErikEJ can you direct me to the original issue/fix?
Meanwhile I'll check your toolbox, thanks.

@ghost
Copy link
Author

ghost commented Jan 10, 2018

Found the other issue and the fix. This previous issue is #9820 - UseDatabaseNames not working in columns names. It was fixed in #9981.

With the fix, the names should match correctly with database when --use-database-names flag is used.
BUT I still doubt if way of PascalCase-ing in CandidateNamingService is right. It'll still produce names (when the above flag is not used) like

DOB >> Dob

@ErikEJ
Copy link
Contributor

ErikEJ commented Jan 11, 2018

Please try the "EF Core Power Tools" https://github.com/ErikEJ/SqlCeToolbox/wiki/EF-Core-Power-Tools and report any missing features or other issues/bugs here: https://github.com/ErikEJ/SqlCeToolbox/issues - maybe we can work together to fulfill your requirements?

@ajcvickers
Copy link
Member

Closing this as duplicate. @chakrabar Changing "DOB" to "Dob" is by-design. It's a pretty common code style to do this, and, for what it's worth, it's even in the Microsoft design guidelines.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants