映射 am:n 关系两次

发布于 2024-10-14 18:52:39 字数 1009 浏览 2 评论 0原文

我想知道是否可以在 EF4 模型中两次映射数据库中的 am:n 关系。

考虑这个数据库模型:

http://andarki.dk/stackoverflow/db.png

它是公司和用户之间标准的 m:n 关系。 如果在模型生成过程中忽略字段works_at.is_locked_out,它会在 EF 中生成良好的 * 到 * 关系:

http: //andarki.dk/stackoverflow/pretty.png

如果我启用works_at.is_locked_out,它看起来更像原始的数据库架构:

http://andarki.dk/stackoverflow/detailed.png

是否可以同时拥有两种关系? 对于某些查询,works_at.is_locked_out 不是必需的,并且拥有直接链接可以更轻松地在这些情况下进行查询。 当我添加这两个关系时,我收到错误

Problem in mapping fragments starting at lines 23, 30:Two entities with possibly different keys are mapped to the same row. Ensure these two mapping fragments map both ends of the AssociationSet to the corresponding columns.
TestModel.edml

这是否有可能,或者这是我试图拥有我的蛋糕并吃它的情况吗?

I am wondering if it is possible to map a m:n relationship in the database twice in a EF4 Model.

Consider this database model:

http://andarki.dk/stackoverflow/db.png

It is a standard m:n relationship between companies and users.
If the field works_at.is_locked_out is ignored during model generation it generates a nice * to * relationship in EF:

http://andarki.dk/stackoverflow/pretty.png

If i enable works_at.is_locked_out it looks more like the original db schema:

http://andarki.dk/stackoverflow/detailed.png

Is it possible to have both relations at once?
For some queries works_at.is_locked_out isn't necessary and having the direct link makes it easier to query in those cases.
When i add both relations i get the error

Problem in mapping fragments starting at lines 23, 30:Two entities with possibly different keys are mapped to the same row. Ensure these two mapping fragments map both ends of the AssociationSet to the corresponding columns.
TestModel.edml

Is this in any way possible or is it a case of me trying to have my cake and eating it too?

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

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

发布评论

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

评论(1

巴黎夜雨 2024-10-21 18:52:39

正如您在出现的错误中看到的那样,两者同时存在是不可能的。 朱莉·勒曼 (Julie Lerman) 的这篇文章将解释很多(如果不是全部的话)。我认为你应该选择替代方案 2,因为正如你所说,它并不总是必要,但有时(或在不久的将来)是必要的。我猜这个字段并不是没有任何目的的……;)祝你好运!

Both at the same time is not possible as you see with the error you are presented. This article by Julie Lerman will explain a lot, if not all. And I think you should go for alternative 2, because as you said it isn't always necessary, but sometimes (or in the near future) it is. That field isn't there without any purpose I guess... ;) Good luck!

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