实体框架4.0关系映射表

发布于 2024-09-18 04:42:58 字数 411 浏览 2 评论 0原文

我有这些桌子;

Customer
- CustomerID (primary key)
- Name

Car
- CarID (primary key)
- Model

Customer_Car_Map (composite primary key CustomerID and CarID)
- CustomerID (foreign key to Customer.CustomerID)
- CarID (foreign key to Car.CarID)

当我使用 EF4 从数据库生成模型时,它会为除 _Map 表之外的所有表生成类。对于这些,它似乎添加了一个 EdmRelationshipAttribute,但不是单独的类。

如何创建并保存新的 Customer_Car_Map?

I have these tables;

Customer
- CustomerID (primary key)
- Name

Car
- CarID (primary key)
- Model

Customer_Car_Map (composite primary key CustomerID and CarID)
- CustomerID (foreign key to Customer.CustomerID)
- CarID (foreign key to Car.CarID)

When I generate the models from the database using EF4, it generates classes for all tables except for the _Map tables. For these it seems to add an EdmRelationshipAttribute, but not separate class.

How would I create and save a new Customer_Car_Map?

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

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

发布评论

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

评论(1

苏辞 2024-09-25 04:42:58

如果实体框架正确完成其工作,则您不需要映射表的类。

实体框架 4 支持多对多关系。它将在代表映射表两侧的任一实体上生成成员。您将使用实体添加关系,实体框架将在幕后利用映射表。

如果这些设施不足以完成工作,我会质疑为什么您需要访问应用程序中如此低级的数据。

If the Entity Framework does its job correctly, you shouldn't need a class for the mapping tables.

Entity Framework 4 supports many to many relationships. It will generate Members on either of the Entities representing the two sides of the mapping tables. You will use the Entities to add relationships and Entity Framework will utilize the mapping table behind the scenes.

If those facilities aren't enough to get the job done, I would question why you need access to such low level data in your application.

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