Assuming I have a child
public class Child
{
public int Id {get; set;}
}
and two parents which using the childs in one to one relations. One child should be used only at one parent. But I want to use the child with Id=1 at ParentA and the child with Id=2 at ParentB for example.
public class ParentA
{
public int Id {get; set;}
public int ChildId {get; set;}
public Child Child {get; set;}
}
public class ParentB
{
public int Id {get; set;}
public int ChildId {get; set;}
public Child Child {get; set;}
}
I want the navigation property at the parents if possible.
I know how to configure a one to one relation when having only one parent because then I would have to add a navigation property in the Child
class and would add the configuration in the OnModelCreating
method of my DbContext
implementation.
But for the scenario with 2+ parents I don't know how the configuration in OnModelCreating
should look like.