EF4 Self referencing with association 0..1 -> 1

ⅰ亾dé卋堺 提交于 2019-12-12 16:59:31

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5152041/ef4-self-referencing-with-association-0-1-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!