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

Capitalized characters in table name not importing correctly #1616

Closed
kchristman54 opened this issue Dec 14, 2022 · 6 comments
Closed

Capitalized characters in table name not importing correctly #1616

kchristman54 opened this issue Dec 14, 2022 · 6 comments
Labels
question Further information is requested

Comments

@kchristman54
Copy link

Database I'm using has lots of tables with capitalized letters, due to abbreviations (like "MECMeter" and "MECModel" and "MECEnergy"). Also, certain columns I need to have renamed when their Entity version is created. Using EF Core Power Tools, I have not been able to both:

  • Import the table names capitalized exactly as they are on the database (instead of just "Mecmeter"), AND
  • Have EF Core Power Tools rename certain columns (e.g., rename MECMeter's "Value" column to be "RawValue").

To be clear, I can do one OR the other in the above 2 bullets.

The only way I have found to get the tables names to come in with their original capitalization, is to enable "Use table and column names directly from the database". (If I don't do that, then I get "Mecmeter", "Mecmodel", "Mecenergy", etc.). But once I enable that, then the ability to F2 on a column name and change it (e.g., from "Value" to "RawValue") no longer actually impacts anything.

I'm attempting to come from EF6, so I've also enabled "Pluralize singular generated object names (English)" and "Use EF6 pluralizer".

Provide steps to reproduce

  1. Create a table with multiple capitalized characters, like "MECMeter".
  2. Add a column to the table, like "Value"
  3. Use EF Core Power Tools to reverse engineer:
    a. Use the F2 feature to rename "Value" to "RawValue"
    b. Enable "Pluralize singular generated object names (English)" and "Use EF6 pluralizer".
    c. Generate the Entity files. Note that results are fine EXCEPT that the class is called "Mecmeter"
  4. Enabling "Use table and column names directly from the database" fixes the class name problem, but then it no longer respects the renaming of the column name.

Provide technical details

  • EF Core version in use: EF Core 6

  • Is Handlebars used: no

  • Is T4 used: no

  • Is .dacpac used: no

  • EF Core Power Tools version: 2.5.1

  • Database engine: SQL Server (database has compatibility set to 2012, server itself is version 13.0.7016.1)

  • Visual Studio version: Visual Studio 2022 (17.4.2)

@ErikEJ
Copy link
Owner

ErikEJ commented Dec 15, 2022

You can also do custom renaming on table level. And you can do bulk renaming based on a regex.

@kchristman54
Copy link
Author

kchristman54 commented Dec 15, 2022

I can confirm that if I make a efpt.renaming.json file like this:

[
   {
      "SchemaName": "dbo",
      "Tables": [
         {
            "Columns": [ ],
            "Name": "MECDatas",
            "NewName": "MECDatas"
         },
         {
            "Columns": [ ],
            "Name": "MECGroups",
            "NewName": "MECGroups"
         },
         {
            "Columns": [ ],
            "Name": "MECMeters",
            "NewName": "MECMeters"
         }
      ],
      "UseSchemaName": false
   }
]

and run it using both "Pluralize singular generated object names (English)" and "Use EF6 pluralizer" enabled, that it indeed matches the names that EF6 EDMX would generate in the past! So I'm happy to find that I can get things to match EF6 behavior.

I think other new users of this tool might also find it confusing that:

  • the "Singularize/Pluralize" feature is doing more than just that, it's also changing the capitalization (e.g., "MECMeter" to "Mecmeter").
  • A user looking at the efpt.renaming.json file shown above might think that it's not doing anything, since the Name and NewName are identical. But it indeed does something behind the scenes when you run with it.

If the capitalization changes are happening in your code (as opposed to EF Core code), maybe adding a "Preserve capitalization" checkbox might clear things up for other people who might run into this?

Using the efpt.renaming.json above, I'm getting results I like, so feel free to close this issue (unless you feel my above bullet points are helpful for any code tweaks). Thanks again for your helpful tool!

@ErikEJ
Copy link
Owner

ErikEJ commented Dec 15, 2022

Maybe Improve the docs of what Pluralizer does? And also enhance the docs of the renaming.json file?

@kchristman54
Copy link
Author

Yeah, I suppose that would help.

What's confusing to me is the order of the operations. The NewName in the renaming.json file is clearly not the final name, since the singularization will result in a singular public partial class MECData (and public partial class MECGroup), without a trailing "s". So clearly the singularization is still happening and operating on the NewName. But somehow having the above renaming.json (which a cursory inspection suggests it's not going to do anything) turns off any of the de-capitalization--which suggests that it is separate from the singularization/pluralizing operations. And of course why the above renaming.json--which a cursory inspection suggests it's not going to do anything because Name==NewName--actually impacts things.

Again, I'm happy with the workaround I have. Just trying to reduce other people from being confused about what the order of operations and what happens when, why the NewName can still be transformed, and why capitalization changes are included with singularizing the class names (unless a NewName is given).

I'm a complete newbie to EF Core--and just 'used' EF 6--so maybe that's part of the problem. Thanks again!

@ErikEJ
Copy link
Owner

ErikEJ commented Dec 16, 2022

The change of MECMeter to Mecmeter always happens, it has not to do with Pluralization. All identifiers are C#-ified by EF Core.

I think the main friction here is that you are in a group of users of this tool that come form EF6 and are not willing to do a clean cut (and/or start with a greenfield approach).

But I am delighted that the tool has enough flexibility to accomodate your EF6 based requirements.

@ErikEJ ErikEJ closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2022
@ErikEJ ErikEJ added the question Further information is requested label Dec 16, 2022
@ErikEJ
Copy link
Owner

ErikEJ commented Dec 16, 2022

I have updated the docs: https://github.com/ErikEJ/EFCorePowerTools/wiki/Reverse-Engineering#custom-renaming-with-efptrenamingjson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants