How to access multiple object in one business object class

How to access multiple object in one business object class

Old forum URL: forums.lhotka.net/forums/t/4037.aspx


amit posted on Friday, December 14, 2007

Hi All  

Can anybody please tell me how to access multiple business objects in one class.

As per my requirment.I have created one business object class file for table Company. but now I want to execute some queries that are related to other tables also. But I don't have  objeect for other class.

e.g

if obj1.Id < obj2.ID then do something.

 

 

KKoteles replied on Friday, December 21, 2007

amit,

Wow.  Not sure where to begin.  For the most part you should be able to look at Rocky's ProjectTracker application for ideas.  The point I try to keep in mind is to keep my object's properties "encapsulated". 

When I need to have properties that are actually associated with another "related" object, then I make sure these properties are Read-Only within the main object (I usually include the ID key to the related object as well).  That way when I need to change the property of the related object - I can open the related object itself to do so. 

There are several different ways to get / hold the related object's ID.  What you usually need is a "bridge" type table - one that holds the relationship between the two objects.  Say your main object is Project and your related object is Resource (should make it easier for you to follow along within ProjectTracker).  You will actually need to define a child object of Project - that being ProjectResources (this holds the values from the "bridge" table).  This is actually an object in and of itself having its own properties (if nothing else it's own ID, and the IDs of the two related objects - in my case I usually have at least the date the relationship was created and who created it as well).  This child object really is nothing other than Read-Only values for display purposes and most importantly the ID value for the related Resource objects.  To actually see the entire related object you would select it from the ProjectResources child list, grab the ID and launch / load the main Resource object.  More likely than not, this object would contain the child object ResourceProjects (Rocky actually calls it ResourceAssignments, but I have trouble remembering that Assignments are actually Projects so I prefer naming it a little different and it is all up to you anyway) - since now Project is a "related" object to the Resource object.

It is all a matter of how you design your objects.

Enjoy,

Ken

Copyright (c) Marimer LLC