この種の関連付けでは、「タイプ 'Foo' と 'Bar' の間の関連付けのプリンシパル エンドを特定できません。この関連付けのプリンシパル エンドは、リレーションシップ fluent API またはデータ アノテーションのいずれかを使用して明示的に構成する必要があります。 "
public class Foo
{
public int Id { get; set; }
public int? MainBarId { get; set; }
public virtual Bar MainBar { get; set; }
[InverseProperty("Foo")]
public virtual ICollection<Bar> Bars { get; set; }
}
public class Bar
{
public int Id { get; set; }
public int FooId { get; set; }
public virtual Foo Foo { get; set; }
public int? OldFooId { get; set; }
public virtual Foo OldFoo { get; set; }
}
ここで、Foo にはバーのコレクションがあり、メイン バー (MainBar) を持つことができます。Bar は常に Foo に関連付けられていましたが、別の Foo (OldFoo) への参照を持つことができました。
- データ注釈を使用してEFでこれをマップする方法は?
- データ注釈では不可能な場合、これを流暢に行う方法は?