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

ForeignKey on navigation property not work #182

Closed
flier268 opened this issue Dec 28, 2022 · 2 comments
Closed

ForeignKey on navigation property not work #182

flier268 opened this issue Dec 28, 2022 · 2 comments

Comments

@flier268
Copy link

public class Parent
{
    [Key, Column(Order = 1)]
    public int Key1 { get; set; }

    [Key, Column(Order = 2)]
    public int Key2 { get; set; }

    public string Name { get; set; } = null!;

    [InverseProperty(nameof(Child.Parent))]
    public virtual IEnumerable<Child>? Children { get; set; }
}

public class Child
{
    [Key]
    public int Id { get; set; }

    public int ParentKey1 { get; set; }
    public int ParentKey2 { get; set; }

    [ForeignKey($"{nameof(ParentKey1)}, {nameof(ParentKey2)}")]
    public virtual Parent? Parent { get; set; }
}
@MoonStorm
Copy link
Owner

That is not a valid construct. You need to have a separate set of parent-child properties for each of foreign key relationships. Check the wiki for some examples.

@flier268
Copy link
Author

flier268 commented Mar 9, 2023

In EF Core, ForeignKey can be added to the child model or parent model, maybe we can support that.
In some case, we will use Dapper and EF Core both with same model.

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

2 participants