0

I have a WorkYear class that should be able to reference the previous or next workyear.

public class WorkYear
{
    public int Id { get; set; }
    public int? PrevId { get; set; }
    public virtual WorkYear Prev { get; set; }
    public int? NextId { get; set; }
    public virtual WorkYear Next { get; set; }

}

The Idea is that one has create 3 workyears A, B and C.

Upon creation of A.

A.prev = null
A.next = null

Upon creation of B,when selected B.Prev = A then A.next becomes = B.

Upon creation of C,when selected C.Prev = B then B.next becomes = C.

With only the Prev in the model all is fine for EF. One can assign a Previous one.

Upon creating a migration to extend the model with Next. EF is protesting :

Unable to determine the principal end of an association between the types 'Mapato.Models.WorkYear' and 'Mapato.Models.WorkYear'. 
The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.

Any suggestions ?

Hidde
  • 11,493
  • 8
  • 43
  • 68
BrilBroeder
  • 1,409
  • 3
  • 18
  • 37

1 Answers1

0

In any relation one end must be principal and second end must be dependent or child. Principal end is the one which will be inserted first and which can exist without the child one. Child is the one which must be inserted/updated after the principal because it has foreign key association to the principal.

following is one of the interesting answer given to the similar question. It might help!!What does principal end of an association means in 1:1 relationship in Entity framework
Community
  • 1
  • 1
Biswabid
  • 1,378
  • 11
  • 26