问题描述
有很多关于自我引用问题的阅读,但我似乎找不到我的问题的答案。
说我有一个人(A),我想要A有一个合作伙伴,另一个人(B)。当然,这意味着B在人类中有一个伙伴A.你会如何解决这个问题?理想情况下,我只需要做:
humanA.Partner = humanB;
,并且humanB将自动将manA作为合作伙伴。
$ b $我会以为我可以创造一个人类,并添加一个协会,如:
所以,每个人都有零个或一个合作伙伴是人类。
感谢你的时间。
1:0..1只有当。这意味着相关实体FK也是其PK。所以自我参考1:0..1不能存在。我想你甚至不能直接在数据库中映射。
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:
So, each human has zero or one Partner which is a human.
Thanks for your time.
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.
这篇关于EF4自身参考与关联0..1 - > 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!