如何设计带有属性的交叉实体的DTO
我想知道如何设计关于具有属性的交集实体(关于多对多关系)的 DTO。
例如,如果有 CAR、PARTS、CAR_PARTS 表,例如
CAR (ID, NAME, ...)
PARTS (ID, NAME, ...)
CAR_PARTS (CARID, PARTSID)
,让 CAR 和 PARTS 具有多对多关系,那么我认为我们可以将 DTO 设计为 就
class Car {
int id;
String Name;
List<Parts> partsList;
}
public class Parts {
int id;
String name;
List<Car> carList; //if necessary
}
可以了。
问题是,如果 CAR_PARTS 表有任何属性,例如
CAR (ID, NAME, ...)
PARTS (ID, NAME, ...)
CAR_PARTS (CARID, PARTSID, QUANTITY)
,这里 QUANTITY 表示汽车中的零件数量,例如如果汽车有 4 个轮胎,则 QUANTITY 为 4,在这种情况下我如何设计 DTO?
在上面的类中,它们将关系表示为具有每个类的属性。所以好像无法表达数量...
I'm wondering How I can design DTO about Intersection Entity (about many-to-many relation) with attribute.
For example, if there was CAR, PARTS, CAR_PARTS table, like
CAR (ID, NAME, ...)
PARTS (ID, NAME, ...)
CAR_PARTS (CARID, PARTSID)
, and let CAR and PARTS have many-to-many relation, then I think we can design DTO as
class Car {
int id;
String Name;
List<Parts> partsList;
}
public class Parts {
int id;
String name;
List<Car> carList; //if necessary
}
It's OK.
The question is, if CAR_PARTS table had any attribute, like
CAR (ID, NAME, ...)
PARTS (ID, NAME, ...)
CAR_PARTS (CARID, PARTSID, QUANTITY)
, and here QUANTITY indicates the parts quantity in a car, for example if a car has 4 tyres then QUANTITY is 4, in this case how I can design DTO?
In the classes above they expresses the relationship as having the property of each class. So it seems not to be able to express quantity...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不制作像
Dictionary这样的字典? partsList;
或制作List; parts;
并具有带有必需属性的 car_parts 类Why not make dictionary like
Dictionary<Parts, Qty> partsList;
or MakeList<CAR_PARTS> parts;
and have car_parts class with required attribute