I have a Foo
that can have two optional references to itself: ParentId
and RootId
.
public class Foo
{
[Key]
public int FooId { get; set; }
public int? ParentId { get; set; }
[ForeignKey(nameof(ParentId))]
public virtual Foo Parent { get; set; }
public int? RootId { get; set; }
[ForeignKey(nameof(RootId))]
public virtual Foo RootFoo { get; set; }
// ...
}
Having one works fine, but when I introduce the second self-reference I get error:
Unable to determine the principal end of an association between the types 'Model.Foo' and 'Model.Foo'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.