从具有额外字段的一对多表设计类

发布于 2024-07-25 11:12:08 字数 306 浏览 6 评论 0原文

如何将数据库中的一对多关系中的任何其他属性建模回类中?

例如我有 3 个表 Model、Manager 和 Model_Manager。 Model_Manager 表具有 ModelId、ManagerId 和两个额外属性 - Percentage 和 Owner。

首先,我创建了两个类 Manager 和 Model,Model 类包含一组 Manager 来捕获 1-Many 链接。

但现在我应该把额外的百分比和所有者属性放在哪里。 即使它不是“实际业务”类,在设计中实际使用 Model_Manager 类是否有意义?

How do I model any additional properties from One-Many relationships in the database back into classes?

For example I have 3 tables Model, Manager and Model_Manager. The Model_Manager table has ModelId, ManagerId and two extra properties - Percentage and Owner.

At first I created two classes Manager and Model and the Model class contains a collection of Managers to capture the 1-Many link.

But now where do I put the additional Percentage and Owner properties. Does it make sense to actually have a Model_Manager class in the design even if it's not a "real-business" class?

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

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

发布评论

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

评论(4

忆沫 2024-08-01 11:12:09

这是带有额外数据的多对多关系。 这通常被建模为两个一对多关系。 所以,是的,您确实需要有一个 Model_Manager 类,尽管您可能会考虑一个更好的名称(ManagedModel?)。 Model 和 Manager 各自与 Model_Manager 具有一对多关系。

This is a many-to-many-relationship with extra data. This is typically modeled as two one-to-many relationships. So yes, you do need to have a Model_Manager class, though you might consider a better name (ManagedModel?). Model and Manager each have a one-to-many relationship with Model_Manager.

笑叹一世浮沉 2024-08-01 11:12:09

听起来您的附加 2 个属性是链接属性,因此应该在模拟 managerID 和 2 个附加字段的类中表示

It sounds like your additional 2 properties are link attributes and should therefore be represented in a class that models the managerID and the 2 addtional fields

狼亦尘 2024-08-01 11:12:09

好吧,想必每个管理器都有一组可以管理一定比例的模型,所以...

我将创建一个 ManagedModel 类,其中包含指向模型对象的指针和附加属性。 然后每个 Manager 可以有一组 ManagedModel 对象。

Well, presumably every Manager has a set of Models that it can manage a percentage of, so...

I would create a ManagedModel class that contains a pointer to a Model object and the additional properties. Then each Manager could have a set of ManagedModel objects.

酒几许 2024-08-01 11:12:09

是的,根据您的描述,ModelManager 类是有道理的。 然后,模型将具有 ModelManager 列表,并且 ModelManager 类将具有经理、百分比和所有者。

Yes, from what you described, a ModelManager class, makes sense. The Model would then have a List of ModelManagers and the ModelManager class would have the Manager, Percentage and Owner.

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