本文介绍了EF4具有关联的自引用0..1 - > 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个大量的阅读自我参照的问题,但我似乎无法找到一个回答我的问题。

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

说我有一个(A),和我想有一个合作伙伴,另一个人(B)。当然,这意味着B有人类A.你将如何解决这个问题的合作伙伴?理想情况下,我应该只需要做的:

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;

和humanB将自动获得Humana公司作为合作伙伴。

and humanB would automatically get humanA as a partner.

我本来以为我可以创造一个人类enity,并添加一个协会,是这样的:

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

END1 实体:的,多重性: 0..1 的,导航属性:合作伙伴

END2 实体:的,多重性: 0..1

End2 Entity:Human, Multiplicity:0..1

所以,每个人都有零个或一个合作伙伴是一个人。

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

感谢您的时间。

推荐答案

1:0..1映射只有在使用的。这意味着,当有关的实体FK也是它的PK。因此,自参考1:0..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.

这篇关于EF4具有关联的自引用0..1 - > 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-04 08:51