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

Model configuration: Shadow primary key should behave the same as non-shadow primary key #7377

Closed
hey-red opened this issue Jan 8, 2017 · 3 comments
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@hey-red
Copy link

hey-red commented Jan 8, 2017

Its possible to use "Single Navigation Property" with shadow primary key?
i.e:

public class A 
{
    public int Id { get; set; }
    public B Data { get; set; }
}

public class B 
{
    public string Text { get; set; }
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<B>().Property<int>("Id");
}
@ajcvickers
Copy link
Contributor

@hey-red Yes, but it looks like currently you have to be more explicit about the relationship:

modelBuilder.Entity<A>()
    .HasOne(e => e.Data)
    .WithMany()
    .HasPrincipalKey("Id");

@hey-red
Copy link
Author

hey-red commented Jan 9, 2017

@ajcvickers
I'm added foreign key and this works. Thx!

// map b
modelBuilder.Entity<B>()
    .Property<int>("Id");

// map a
modelBuilder.Entity<A>()
    .HasOne(e => e.Data)
    .WithOne()
    .HasForeignKey<B>("AId")
    .IsRequired();

Also, maybe has another way to achieve shadow a principal key and foreign key in map b?

@hey-red hey-red closed this as completed Jan 9, 2017
@ajcvickers
Copy link
Contributor

Re-opening as the original case threw an exception, which was not the behavior I expected.

@ajcvickers ajcvickers reopened this Jan 9, 2017
@rowanmiller rowanmiller added this to the 2.0.0 milestone Jan 17, 2017
AndriySvyryd added a commit that referenced this issue Feb 4, 2017
Rediscover primary key if the matched property is ignored.

Fixes #7377
AndriySvyryd added a commit that referenced this issue Feb 6, 2017
Rediscover primary key if the matched property is ignored.

Fixes #7377
AndriySvyryd added a commit that referenced this issue Feb 6, 2017
Rediscover primary key if the matched property is ignored.

Fixes #7377
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Apr 13, 2017
@AndriySvyryd AndriySvyryd removed their assignment Apr 13, 2017
@ajcvickers ajcvickers changed the title Shadow primary key Model configuration: Shadow primary key should behave the same as non-shadow primary key May 9, 2017
@divega divega added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels May 10, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

5 participants