简体   繁体   中英

Designing classes from One-Many table with extra fields

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?

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.

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM