EF4 自引用关联 0..1 -> 1

发布于 2024-10-19 20:04:09 字数 471 浏览 3 评论 0原文

关于自引用问题有很多阅读,但我似乎找不到我的问题的答案。

假设我有一个人类(A),并且我希望 A 有一个伙伴,即另一个人类(B)。自然,这意味着B有人类A的伴侣。你会如何解决这个问题?理想情况下,我只需要这样做:

humanA.Partner = humanB;

并且 humanB 会自动让 humanA 作为合作伙伴。

我本以为我可以创建一个人类实体,并添加一个协会,例如:

End1 实体:人类,多重性:0..1,导航属性:合作伙伴

End2 实体:人类,多重性: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:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

り繁华旳梦境 2024-10-26 20:04:09

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文