wwBusinessPro – Article 2: Configuring Child classes (wwBusProItemList)

Note: This post if part of a complete series on the West Wind wwBusiness library.
Click here to see the full index

Another enhancement I added to wwBusinessPro was to allow for Child record collections to be easily used with a Parent BO.

When using a wwBusProParent, you set a few properties on the Parent that tell it about the Child class. Then, the Parent will create the Child class for you. So, when you’re working with your BO’s in code (after everything is all configured), you do not create the Child, you let the Parent do that. You will create a VCX library and add a Child class for each Child collection in there (based on wwBusProItemList), with its Child properties already set up. This allows the Parent to create the Child when he needs it. So you can see how this works, if you were to follow the path of the Get() method (remember, this is a key extension method I added in wwBusProParent), you will see that the Parent creates the Child object and attaches it to its oLineItems property. So, once your Child classes are configured in a VCX, you will not actually have to write any code to access them (unless you are doing some special case, custom coding), you just set up the Parent so he can find them. The Parent will handle all that for you, including the fetching of the related Child records.

Code Sample: Creating and using your first Parent Business Object

Parent Setup:

When using a wwBusProParent, you set properties on the Parent that tell it about the Child class.
Then, the Parent will create the Child class for you.
You do not create the Child when writing your code, let the Parent do that.

You need to create a VCX library and put a Child class for each Child collection in there,
with its Child properties already set up. This allows the Parent to create the Child when he
needs it. If you follow the path of the Get() method, you will see that the Parent creates a
Child class object and attaches it to its oLineItems property. So, once your Child classes are
configured in a VCX, you will not actually have to write any code to access them (unless you are
doing some special case, custom coding), you just set up the Parent so he can find them.
The Parent will handle all that for you, including the fetching of the related Child records.

You can also put your Parent objects in the VCX and set their properties in the VCX file.
This sample code is shown here simply to show which properties are required to make it all work.

Child Setup

When setting up your Child in the VCX, these are the properties you need to set on it:

cFilename (Required. Name of the dbf or Sql Server table)
cAlias (Optional. Will use cFilename by default)
cPKField (Must be an Integer. See “Important Note” below)
cFKField (Must be an Integer. Maps to Parents PK field)
cLookupField (Optional. Maps to Parents cLookupField. Use when Parent uses for String lookups)
cOrderFld (Optional. Can be used to set the ordering of child records. i.e. a sequnce field)

These properties provide the info needed by the LoadLineItems() method work out of the box.
Sometimes you may want to overwrite the LoadLineItems() method with custom code, but the default
should work in basic configurations.

IMPORTANT NOTE:
In order to save changes on the Child records, they need a unique PK that can be used. See cPKField.
String cLookupField works fine to load the records in, but it does not guarantee uniqueness when
trying to save changes back.

Again, you can use cLookupField Stings for loading the records, but you must have Integer PKs
on your Child records to allow saving changes back.

Leave a Reply

Your email address will not be published. Required fields are marked *