Hi,
I have a question about class design. Currently I am working with following tables:
=======================
| Forms
=======================
| FormID (PK)
| CommitmentID (FK)
| ...
---------------------------
=====================
| Commitments
=====================
| CommitmentID (PK)
| CommitDesc
| ...
---------------------------
=====================
| Pricings
=====================
| PricingID (PK)
| Desc
| CommitmentID (FK)
| ...
---------------------------
=====================
| PricingTiers
=====================
| TierID (PK)
| PricingID (FK)
| Desc
| ...
---------------------------
MAPPING:
Forms <-one to one-> Commitment
Commitment <-one to many-> Pricing
Pricing <-one to many-> PricingTiers
When designing the classes what would be considered a best practice ... for instance at the moment I have 4 classes "Form", "Commitment", "Pricing", and "PricingTier" respectively.
Form class has a public property Commitment which represents an instance of the Commitment class.
Commitment class has a public property List<Pricing> which represents the one to many (Commitment - Pricing) relationship.
Also, Pricing class has a public property List<PricingTier> which represents the one to many (Pricing - PricingTier).
After designing these classes the very first problem that I noticed was that I can't use a PK to access the objects instead I will have to loop over the objects to find the one I am looking for (this is because I have exposed one to many relatioship using List<T>).
OR access these objects using indexes:
Forms frms = Forms(55);
PricingTiers pt = frms.Commitment.Pricing[45].PricingTiers[0];
Ideally I would like to be able to access "Pricing" or "PricingTier" objects using the Primary Key (PricingID or PricingTierID).
I thought about exposing these properties using generic Dictionary<int, Pricing> where the PricingID would be the Key. Would that be a good idea?
Do you guys have any suggestions? or can any of you point me in the right direction?
Thanks!