私はEF6コードこのような最初のモデルデザインを持っています。 Another
クラスから親(ParentA
またはParentB
)を知る最も良い方法は何ですか。ありがとうございます!EF複数の小鳥のための1人の子供
public class Child
{
public int Id { get; set; }
public List<Another> AnotherList { get; set; }
}
public class Another
{
public int Id { get; set; }
public int ChildId { get; set; }
public Child Child { get; set; }
public string AnotherName { get; set; }
}
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; }
}
public class Context : DbContext
{
public DbSet<ParentA> ParentA { get; set; }
public DbSet<ParentB> ParentB { get; set; }
public DbSet<Child> Child { get; set; }
public DbSet<Another> Another { get; set; }
}
'Child'は' ParentA'と 'ParentB'プロパティを必要とし、これを2つの1:1関連に変換します。私は代案を多相協会といいますが、それが絶対必要でない場合はそうしません。 –