question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reverse Engineer - Rename navigation and reference properties

See original GitHub issue

Is it possible to rename the generated navigation properties?

Steps to reproduce

Say there are two tables,

CREATE TABLE Product ( Id UNIQUEIDENTIFIER NOT NULL PRIMARY KEY, CategoryCode VARCHAR(20) FOREIGN KEY (CategoryCode) REFERENCES Category (Code) NULL, ParentId UNIQUEIDENTIFIER FOREIGN KEY (ParentId) REFERENCES Product (Id) NULL )

CREATE TABLE Category ( Code VARCHAR(20) NOT NULL PRIMARY KEY, Description VARCHAR(100) NOT NULL )

Product table references both Category and Product itself. The generated class contains the following navigation properties, which I very much want to rename to something more meaningful.

public Category CategoryCodeNavigation { get; set; } public Product ParentProduct {get;set;} public virtual ICollection<Product> InverseProduct {get; set;}

I have tried to use efpt.renaming.json, but it only supports renaming columns not FK relations.

I understand I can just manually rename the properties after the code-gen, but the changes will be overwritten when the project is re-generated which we do quite often.

So is there a workaround to rename FK navigation properties?

Thanks for any tips!

Further technical details

EF Core Power Tools version: (found in About dialog - blue questionmark icon on context menu) 2.2.12.0

Database engine: (SQlite, SQL Compact, SQL Server, Postgres) Azure SQL

Visual Studio version: (e.g. Visual Studio 2017 15.7) VS2019

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:52 (23 by maintainers)

github_iconTop GitHub Comments

4reactions
ErikEJcommented, Oct 25, 2020

Not something I plan to implement

2reactions
ErikEJcommented, Nov 3, 2022

Another attempt at this is now in preview, more confidence this time (using Roslyn for consisten renaming) - https://github.com/ErikEJ/EFCorePowerTools/wiki/Reverse-Engineering#custom-renaming-with-efptproperty-renamingjson

Read more comments on GitHub >

github_iconTop Results From Across the Web

Improve navigation property names when reverse ...
I'm using Entity Framework 5 with Visual Studio with Entity Framework Power Tools Beta 2 to reverse engineer moderately sized databases (~100 ...
Read more >
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 >
EF Core Power Tools database reverse engineering
... EF Core), includes a feature to rename entities and properties. ... database reverse engineering: renaming of entities and properties.
Read more >
Entity-framework – Improve navigation property names ...
I'm using Entity Framework 5 with Visual Studio with Entity Framework Power Tools Beta 2 to reverse engineer moderately sized databases (~100 tables)....
Read more >
5 Creating and Reverse-Engineering a Model
This chapter describes how to create a model, how to reverse-engineer this model to populate it ... A Reference is a functional link...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found