EntityFrameworkCore.Generator icon indicating copy to clipboard operation
EntityFrameworkCore.Generator copied to clipboard

Navigation Propery Name

Open taraman opened this issue 6 years ago • 3 comments

Dear all I like this tool as it generates entities for database views and can customize the output. the tiny issue I got when using Scaffold-DbContext for reverse engineering: public Patent() { public virtual ICollection<Inventor> Inventors { get; set; } } but when generate with the generator tool, I got this: public Patent() { public virtual ICollection<Inventor> PatentInventors { get; set; } }

as you see the class name Patent has been concatenated to the property name, so can we have any custom way to keep only the navigation property name?

taraman avatar Dec 26 '19 12:12 taraman

If you refactor and rename the property, the changes should be kept upon re-generation. Is that not the case?

pwelter34 avatar Dec 30 '19 03:12 pwelter34

Navigation properties (generated relationships) are not being preserved upon re-generation even after renaming them through the IDE. The renamed properties revert back to the default auto generated names.

For example:

public partial class Person { ... }

public partial class User { #region Generated Properties public int PersonID { get; set; } public string Email { get; set; } // can rename this property just fine and the change is preserved upon re-generation #endregion #region Generated Relationships public virtual Person FKPersonPerson { get; set; } // needs to be renamed to Demographics but the name reverts back after re-generation #endregion }

How can I rename the generated relationship property to the desired name and preserve said change so a re-generation won't revert it back?

ehpmfigueroa avatar Mar 30 '23 20:03 ehpmfigueroa

@pwelter34 Currently renaming of 'generated relationships' are reverted upon regeneration. Is it possible to extend the 'renaming functionality' so

  • a rename entry can also pass a 'replacement string'. This way we can specify a match (like now) and also a replace (which is currently string.empty in your code)
  • rename functionality also applies on 'generated relationships'. This way we can specify our renames in the yaml and regeneration won't revent them.

fyi I would like the rename functionality for generated relationships for the following example (hierarchical table):

class Project
{
    Guid Id  { get; set; }
    Guid? ParentProjectId  { get; set; }
    //Generated relationships
    virtual Project ParentProject  { get; set; }
    virtual ICollection<Project> ParentProjects  { get; set; }  //=> I want this to be named 'ChildProjects'
}

ArnaudB88 avatar Mar 20 '24 12:03 ArnaudB88