来自与联结表连接的 2 个表的 EF 模型 - 模型看不到联结表中的记录和更改

发布于 2024-08-20 20:35:45 字数 631 浏览 7 评论 0原文

我的 SQL2008 数据库中有几个表,其中包括 Managers(ManagerID 是 PK,增量)和 Customers(CustomerID 是 PK,增量)。所有 ID 列均为 int。它们与联结表ManagersCustomers(字段:CustomerID是PK,ManagerID)连接,并且存在关系:从Customers中的CustomerID到具有删除级联规则的联结表中的相同,以及从Managers中的ManagerID到具有删除级联的联结表中的相同。因此,从数据库生成后,我的 edmx 模型中有 Managers 0..1 到 * Customers 关系,我可以看到该关系映射到联结表。我在 SQL Server Management Studio 中测试了联结表,它工作正常。好的。 在我的应用程序中,我有两个部分 - 服务器端的 edmx 模型通过 WCF 数据服务与客户端连接。在客户端部分,我正在创建实体类的实例,在调试模式下,我可以观察实体类实例的数据。实体 Customers 和 Manager 都正确填充了数据,但在导航字段中我只能看到 0。例如,我有 CustomerID = 1 的 Customer 与 ManagerID = 3 的 Manager 连接,并且联结表中有一条记录。因此,如果它能正常工作,我会在客户实体的导航字段中看到我的经理,并且与经理实体中的客户导航字段相同。但我只能看到零。

I have several tables in my SQL2008 DB, Managers(ManagerID is a PK, incremental) and Customers(CustomerID is a PK, incremental) are among them. All ID columns are int. They are connected with junction table ManagersCustomers(fields: CustomerID is a PK, ManagerID) and there are relations: from CustomerID in Customers to same in junction table with delete cascade rule and from ManagerID in Managers to same in junction table with delete cascade too. So I have Managers 0..1 to * Customers relation in my edmx model after generating it from my DB and I can see this relation is mapped to junction table. I tested junction table in SQL Server Management Studio, it works correctly. Ok.
In my app I have 2 parts - edmx model on server side connected with client side through WCF Data Service. In client part I'm creating instance of my entities class, and in debug mode I can watch entities class instance's data. Both entities Customers and Managers are filled with data correctly, but in navigation fields I can see only 0. For example I have Customer with CustomerID = 1 connected with Manager with ManagerID=3 and there is a record in junction table. So, if it would work correctly, I would see my manager in navigation field of Customers entity and same with customer nav field in Managers entity. But I can see only zeros.

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

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

发布评论

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

评论(1

仙女山的月亮 2024-08-27 20:35:45

最简单的方法是更改​​ ManagersCustomers 表,使两列都成为 PK 的一部分,然后重新创建模型。 GUI 设计者不会将其视为多对多关联,除非您这样做。

The easiest thing to do is to change the ManagersCustomers table so that both columns are part of the PK, and then recreate your model. The GUI designer won't pick it up as a many-to-many association unless you do.

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