ErikEJ / EFCorePowerTools

Entity Framework Core Power Tools - reverse engineering, migrations and model visualization in Visual Studio & CLI
MIT License
2.16k stars 295 forks source link

NewName Option not Working #1767

Closed krossley closed 1 year ago

krossley commented 1 year ago

Describe what is not working as expected.

I can't get the "NewName" flag to work.

Please include a complete description or project that I can redo/run to reproduce the issue.

{ "CodeGenerationMode": 3, "ContextClassName": "CoinCatalogContext", "ContextNamespace": null, "DefaultDacpacSchema": null, "FilterSchemas": false, "IncludeConnectionString": true, "ModelNamespace": null, "OutputContextPath": null, "OutputPath": "Entites", "PreserveCasingWithRegex": true, "ProjectRootNamespace": "ReflectionApp", "Schemas": null, "SelectedHandlebarsLanguage": 0, "SelectedToBeGenerated": 0, "Tables": [ { "Name": "[dbo].[Buffalo Nickel NGC]", "NewName": "[dbo].[Buffalo Nickel NG]", "ObjectType": 0 }, { "Name": "[dbo].[Buffalo Nickel PCGS]", "ObjectType": 0 } ], "UseSchemaName": false, "UiHint": "BRYANS-X1\\SQLEXPRESS.CoinCatalog", "UncountableWords": null, "UseBoolPropertiesWithoutDefaultSql": false, "UseDatabaseNames": false, "UseDateOnlyTimeOnly": false, "UseDbContextSplitting": false, "UseFluentApiOnly": true, "UseHandleBars": false, "UseHierarchyId": false, "UseInflector": false, "UseLegacyPluralizer": false, "UseManyToManyEntity": false, "UseNoDefaultConstructor": false, "UseNoObjectFilter": false, "UseNodaTime": false, "UseNullableReferences": false, "UseSchemaFolders": false, "UseSpatial": false, "UseT4": false }

ErikEJ commented 1 year ago

Remove the schema name and brackets

krossley commented 1 year ago

Erik, Thank you for your reply. I have tried what you suggested but I was not able to get it to work. Below is the code where I removed the Schema flag.

` "CodeGenerationMode": 2, "ContextClassName": "CoinCatalogContext", "ContextNamespace": null, "DefaultDacpacSchema": null, "FilterSchemas": false, "IncludeConnectionString": true, "ModelNamespace": null, "OutputContextPath": null, "OutputPath": "Models", "PreserveCasingWithRegex": true, "ProjectRootNamespace": "ReflectionApp",

"SelectedHandlebarsLanguage": 0, "SelectedToBeGenerated": 0, "Tables": [ { "Name": "[dbo].[Buffalo Nickel NGC]", "NewName": "[dbo].[Buffalo Nickel NG]", "ObjectType": 0 }, { "Name": "[dbo].[Buffalo Nickel PCGS]", "ObjectType": 0 } ], "UiHint": "bryans-x1\sqlexpress.CoinCatalog.dbo", "UncountableWords": null, "UseBoolPropertiesWithoutDefaultSql": false, "UseDatabaseNames": false, "UseDateOnlyTimeOnly": false, "UseDbContextSplitting": false, "UseFluentApiOnly": true, "UseHandleBars": false, "UseHierarchyId": false, "UseInflector": false, "UseLegacyPluralizer": false, "UseManyToManyEntity": false, "UseNoDefaultConstructor": false, "UseNoObjectFilter": false, "UseNodaTime": false, "UseNullableReferences": false, "UseSchemaFolders": false, "UseSpatial": false, "UseT4": false }`

ErikEJ commented 1 year ago

Let me be more precise ( and suggest you read the wiki!)

You need to replace

  [dbo].[Buffalo Nickel NGC]

With

   Buffalo Nickel NGC
krossley commented 1 year ago

Erik, Thank you for your reply. I read the wiki first before contacting you. This is what I have tried without success.

` "Tables": [ { "Name": "[dbo].[Buffalo Nickel NGC]", "NewName": "Buffalo Nickel NG", "ObjectType": 0 },

I also tried this "Tables": [ { "Name": "Buffalo Nickel NGC", "NewName": "Buffalo Nickel NG", "ObjectType": 0 },`

ErikEJ commented 1 year ago

Please share your create table statement
The second attempt might work, but unsure about all the spaces in the name

krossley commented 1 year ago

Erik, I have attached a file with a SQL statement that can be used to create the database table. I hope this is what you needed.

USE [CoinCatalog].txt

ErikEJ commented 1 year ago

You need to re-read the wiki. the replacements need to go in a seperate file - and you cannot use spaces in C# names.

https://github.com/ErikEJ/EFCorePowerTools/wiki/Reverse-Engineering#custom-renaming-with-efptrenamingjson

krossley commented 1 year ago

Erik, It's still not working. I will update on it later tonight.

krossley commented 1 year ago

Erik, One problem that I noticed is I did not have a JSON file called efpt.renaming.json . I created the file and use the code below. I have not been able to change the name.

`[ {

"SchemaName": null,

"TablePatternReplaceWith": null,
"TableRegexPattern": null,
"Tables": [
  {

    "Name": "BuffaloNickelNgc",
    "NewName": "BuffaloNickelNGc"
  }
],
"UseSchemaName": false

} ]`

ErikEJ commented 1 year ago

The original name is the full table name. I think.

krossley commented 1 year ago

Erik, "Name": "BuffaloNickelNgc", //This code is what your tool named it on the reverse engineer of the table. "NewName": "BuffaloNickelNGc" // This is what I am trying to rename too. notice the NGc opposed to Ngc. Does the above code in the JSON file above look correct?

ErikEJ commented 1 year ago

I will have another look, not sure if a change in just casing works.

ErikEJ commented 1 year ago

You need to use

           "Name": "Buffalo Nickel NGC",
          "NewName": "BuffaloNickelNgc"
krossley commented 1 year ago

Erik, That did the trick! Sorry that was such a hassle. Than you so much for your help,

ErikEJ commented 1 year ago

Cool! If you like my free tools, I would be very grateful for a rating or review on Visual Studio Marketplace or even a one-time or monthly sponsorship

krossley commented 1 year ago

Done! and Done! Thanks again Erik!