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

Scaffolded navigation property name no longer meaningful when using composite foreign keys #659

Closed
tylercamp opened this issue Oct 2, 2018 · 4 comments

Comments

@tylercamp
Copy link

When using single-column foreign keys, I would get navigation properties with useful names such as:

    // fk_army_at_home_id: current_village.army_at_home_id -> current_army.army_id
    public CurrentArmy ArmyAtHome { get; set; }
    // fk_army_owned_id: current_village.army_owned_id -> current_army.army_id
    public CurrentArmy ArmyOwned { get; set; }
    // Same formatting for the rest
    public CurrentArmy ArmyRecentLosses { get; set; }
    public CurrentArmy ArmyStationed { get; set; }
    public CurrentArmy ArmySupporting { get; set; }

(Where current_army table has primary key army_id)

After changing the primary keys to be composite for these tables and setting the foreign keys as composite accordingly, I get generic, uninterpretable names such as:

    // fk_army_at_home: current_village.(world_id,army_at_home_id) -> current_army.(world_id,army_id)
    public CurrentArmy CurrentArmy { get; set; }
    // fk_army_owned: current_village.(world_id,army_owned_id) -> current_army.(world_id,army_id)
    public CurrentArmy CurrentArmy1 { get; set; }
    // Same formatting for the rest
    public CurrentArmy CurrentArmy2 { get; set; }
    public CurrentArmy CurrentArmy3 { get; set; }
    public CurrentArmy CurrentArmyNavigation { get; set; }

(Where current_army table has composite primary key world_id,army_id)

Setting the new foreign keys to have the same naming convention as the original sample (suffixed with _id) has no effect.

@tylercamp tylercamp changed the title Navigation property no longer meaningful when using composite foreign keys Navigation property name no longer meaningful when using composite foreign keys Oct 2, 2018
@tylercamp tylercamp changed the title Navigation property name no longer meaningful when using composite foreign keys Scaffolded navigation property name no longer meaningful when using composite foreign keys Oct 2, 2018
@austindrenski
Copy link
Contributor

Could you give us an example of what the "meaningful" name would be in the composite key scenario?

@tylercamp
Copy link
Author

In this case the naming would optimally match the previous naming (aka the names would be unchanged)

This could be pulled from the name of the foreign key, which generally follows the same naming between the two versions (stripping the fk_ and _id parts of the foreign key name)

@tylercamp
Copy link
Author

Naming as a combination of the two columns in the composite key would also be acceptable, though for my case I'd prefer naming based on the name of the foreign key

@roji
Copy link
Member

roji commented Oct 2, 2018

This seems to be a general EF Core request/question, not related to Npgsql specifically - so it belongs in http://github.com/aspnet/EntityFrameworkCore/.

@roji roji closed this as completed Oct 2, 2018
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