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;
Str开发者_JS百科ing 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...
Why not make dictionary like Dictionary<Parts, Qty> partsList;
or Make List<CAR_PARTS> parts;
and have car_parts class with required attribute
精彩评论