Dear all,
I'm a little new at this so please excuse my ignorance and potential stupid questions. What I'd like to determine is whether I should be creating parent-child-grandchild relationships, or whether I am going about my design approach incorrectly using the CSLA Framework.
I have a BusinessBase class instance called vehicleProgression. This object is a root object and contains many data members and accessors. One of the data members is a strongly typed collection of BuildScheduleItems which is called BuildSchedule; it is inherited from the BusinessListBase class. Before an instance of a BuildScheduleItem can be saved (one of the items contained within the BuildSchedule) it needs to be validated to make sure that it complies with it's rule-set. In order to do so the BuildScheduleItem needs to obtain data from its grand-parent, the vehicleProgression instance.
A little background may help. A vehicleProgression class instance is a facade for existing data from another system - it basically tracks the progress of a vehicle's purchase and re-sale (for a vehicle trader). I.e. a vehicle is bought, sent to a set of locations to have work undertaken on the vehicle, and is eventually sold. The BuildSchedule is a collection of locations to which the vehicle must visit in order to have work undertaken and a BuildScheduleItem is information that specifically relates to the place at which the vehicle is to be worked upon - i.e. Location, estimated arrival date, estimated departure date, etc.
Where was I?...Oh, yes...So, in order for a BuildScheduleItem to validate itself (i.e. estimated arrival date is correct) it needs to communicate with the vehicle progression object to determine when the vehicle was purchased by the dealer - as in this case, a vehicle cannot be worked upon at a specific location until it has been purchased. The purchase date is contained within the vehicleProgression (at root level). Therefore, the BuildScheduleItem needs to be able to communicate with it's grand-parent (as its parent is the BuildSchedule (inheritied from BusinessListBase) collection) to determine whether it's dates are valid.
Now, my approach to this is to the expand the BuildSchedule (which is inherited from the BusinessListBase) so that the BuildScheduleItem can execute code similar to...
_parent <--This gives a reference to the BuildSchedule
.Parent (internal proprerty) <-- This gives reference to the vehicleProgression
.GetPurchaseDate()
So, it would look similar to this:
_parent.Parent.GetPurchaseDate();
However, the BusinessListBase does not contain a variable to hold a reference to the parent. I would imagine that this is by design - so this raises alarm bells in my head. Is this the way that I should be tackling this problem? Or, have I put the cart before the horse once again?
I'd really appreciate any help anyone may offer.
Thank you.
Craig.
Is it possible that we could get away with just marking the _parent field NotUndoable and not marking it NonSerialized? I just did a quick test, with a child holding a reference to his parent with the NotUndoable attribute. Everything seemed to stay intact with no errors after serialization/deserialization, so it looks like the serialization and deserialization handles the circular reference ok. Does anyone see any problems doing this?
Copyright (c) Marimer LLC