2

There's a lot of reading on self referencing problems, but I can't seem to find an answer to my question.

Say I have a Human(A), and I want A to have a partner, another Human(B). Naturally, it means that B has a partner in human A. How would you solve this? Ideally, I should only have to do:

humanA.Partner = humanB;

and humanB would automatically get humanA as a partner.

I would have thought I could create a Human enity, and add an Association, something like:

End1 Entity:Human, Multiplicity:0..1, Navigation Property:Partner

End2 Entity:Human, Multiplicity:0..1

So, each human has zero or one Partner which is a human.

Thanks for your time.

Community
  • 1
  • 1
cederlof
  • 7,206
  • 4
  • 45
  • 62

1 Answers1

0

1:0..1 mapping is possible only when entities "share" primary key. It means when the related's entity FK is also its PK. So self referencing 1:0..1 cannot exist. I think you can't even map it in database directly.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • Both entities do share the same key (both Human entities). Partner is simply the navigation property name. – Morten Mertner Mar 01 '11 at 13:02
  • @Morten: No they don't. In this type of relation they have to share PK value - obviously you can have two entities with same PK value in one table. – Ladislav Mrnka Mar 01 '11 at 13:15