Hi All,
Here are my classes :
class PriceScale
-int ID
-float bookingFees
-Product product
-List<PricePeriod> periods
Class Product
-int ID
-string name
-List<PriceScale> priceScales
class PricePeriod
-DateTime begin
-DateTime end
-float price
-PriceScale scale
As you can see I strictly applied business rules "A product as many price scales, and a price scale has many period".
My problem : for instance when I'm dealing with the Product class I don't like to ask myself "Is the priceScales loaded ?" (cause I won't load it every time I need a product)
Solution :
1/ Lazy loading : I don't like it, cause you run sql query without even knowing it, and you can end up with a 1+n query problem (I'm working on the price computing system so I really need to be sure of which sql query is executed)
2/ Always load it : I don't like it, cause if I apply this logic to everything I'll end up loading the whole database.
3/ Remove the composition (ie the member priceScales),in that case what is the best way to deal with price scale :
get a Dictionnary<int,List<PriceScales>> where the key is the product id ?
something else ?
4/ Add at the beginning of my method where I need the priceScales
checkPriceScalesAreLoaded(productList);
It looks like lazy loading, but it's more explicit.
5/ Something else I didn't even think about :)
Thanks