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

Naming issue in Reverse engineering of a DB #128

Closed
DaniRK opened this issue Nov 18, 2018 · 5 comments
Closed

Naming issue in Reverse engineering of a DB #128

DaniRK opened this issue Nov 18, 2018 · 5 comments

Comments

@DaniRK
Copy link

DaniRK commented Nov 18, 2018

Thanks for a great tool!

Reverse engineering of a DB:
We try to migrate from EF6 to EF Core.
It seems currently there is no way to get both the following results:
Singularize/Pluralize and also disable the EF Core urge to "properly" Camelize/Pascalize names.
Changes in the DB occur quite often, so that reverse engineering will happen over and over again. Therefore it does not make sense to adjust the existing code base manually each time again.

Steps to reproduce

DB table "Notifications"
Column name: SMSRecepient, ...

in EF6, from which we migrate, with Pluralize option:
DbSet name: Notifications
POC Class name: Notification
Property names: SMSRecepient

Power Tools, with option "Pluralize/Singularize" checked:
DbSet name: Notifications
POC Class name: Notification
Property names: SmsRecepient (! Camelization/Pascalization)

Power Tools, with option "Use table and column names from the database" checked:
DbSet name: Notifications
POC Class name: Notifications (! wrong semantic)
Property names: SMSRecepient

There is currently no option in Power Tools to combine the two options

Further technical details

Toolbox/Power Tools version: 1.0.664
Database engine: SQL Server
Visual Studio version 15.7.4, SSMS 17.7)

@ErikEJ
Copy link
Owner

ErikEJ commented Nov 18, 2018

I was able to fix this as follows:

Table Schema:

CREATE TABLE [dbo].[Notifications]
(
	[Id] INT NOT NULL PRIMARY KEY,
	[SMSRecepient] nvarchar(50) NULL
)

I then added a json file in same location as epft.config.json, named efpt.renaming.json
(see a sample file here: https://github.com/ErikEJ/EFCorePowerTools/blob/master/src/GUI/EFCorePowerTools/efpt.renaming.json )

[
  {
    "UseSchemaName": false,
    "SchemaName": "dbo",
    "Tables": [
      {
        "Name": "Notifications",
        "Columns": [
          {
            "Name": "SMSRecepient",
            "NewName": "SMSRecepient"
          }
        ]
      }
    ]
  }
]

I then ran Reverse Engineer with Pluralization enabled.

This resulted in the following POCO class:

    public partial class Notification
    {
        public int Id { get; set; }
        public string SMSRecepient { get; set; }
    }

And this DbSet:

public virtual DbSet<Notification> Notifications { get; set; }

@ErikEJ ErikEJ transferred this issue from ErikEJ/SqlCeToolbox Nov 18, 2018
@ErikEJ
Copy link
Owner

ErikEJ commented Nov 18, 2018

Thanks user @tomzre !!

@DaniRK
Copy link
Author

DaniRK commented Nov 19, 2018

Hi, thanks.

Seems there was a misunderstanding:

  1. I gave only a single example to explain, but this is a huge and always evolving DB where we have some 100 fields where the renaming gives us problems. It does not make much sense to maintain now changes in the DB also in an additional json file.

  2. This was actually more a hint that this functionality is missing in the tools

  3. In the mean time I found that this is actually rather simple to achieve in your tools:, something in the line of :
    public void ConfigureDesignTimeServices(IServiceCollection services)
    {
    services.AddSingleton<IPluralizer, MyPluralizer>();
    services.AddSingleton<ICandidateNamingService, CustomCandidateNamingService>();
    }
    Where the idea is that a CustomCandidateNamingService overrides the renaming.
    Will give you details if you like so

@ErikEJ
Copy link
Owner

ErikEJ commented Nov 19, 2018

Re 1 and 2: Thanks, I am aware of this limitation - EF Core Power Tools use the built-in Scaffolding in EF Core, and is subject to any issues and limitations caused by this.

re 3: Yes, this is what using the json file allows you to control. (The behavior of the CandidateNamingService) 😄 - keep in mind that the tool does not run any code in your project.

@dharmaturtle
Copy link

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

No branches or pull requests

3 participants