Ich habe EF6 Code Erste Modell-Design wie folgt. Was ist der beste Weg zu wissen, wer ein Elternteil ist (ParentA
oder ParentB
) von Another
class.Thank!EF Ein Kind für Multiply Parrents
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' benötigt eine 'ParentA'- und eine' ParentB'-Eigenschaft und wandelt diese in zwei 1: 1-Zuordnungen um. I Die Alternative wird polymorphe Assoziationen genannt, aber ich würde das nicht tun, wenn es nicht unbedingt notwendig ist. –