Business Objects

fredriko

Active member
Joined
Jun 3, 2004
Messages
35
Programming Experience
10+
I am currently banging my head against a wall as to what is the best solution for the following problem. Any help/advice you can provide me with will be greatly appreciated.
I have an application which will contains two collections of objects. People and Companies. I wish to maintain a list of all the companies and all the people in memory at any one time (for performance reasons - duplication is not an issue).
I want to be able to loop through the people collection in two ways. By Person and By Company.
If I want to populate a list with all people I can simply loop through the single people collection. If however I want to loop through all the people associated with a company I have to loop through every person, check if they belong to a company and display them. I would prefer to have a seperate company employees collection in the company class but doing this means duplicating objects over and over.
Can anybody help me untangle this mess in my brain.

Cheers
 
Put all your data into DataTables instead of Collections. You can then use the Select() method to get an array of rows that match a particular criteria, or a better solution would be to create a DataView for the table using the DefaultView property and then use the RowFilter property of the DataView to expose only the rows you want. If there is a relationship between the People and Companies then you can use a DataSet to represent the relationship as well as the data. That may or may not be useful in this case.
 
Note that the DataView class also has a Sort property. If you are not already familiar with the DataView class, the RowFilter takes a String that is a valid SQL WHERE clause and the Sort property takes a String that is a valid SQL ORDER BY clause. If you like this idea but are not sure how to proceed, let me know and I will post some code.
 
Also, if you stay with the original business objects approach, you may want to look at inheritance as VB.NET is truely object oriented now. Create base classes of person, then inherit from it to create a more specific class.
 
The functionality of the DataView (being able to filter) would probably work however I am using custom collections (inheriting from DictionaryBase) for the implementation of People and Companies.

If I could somehow apply the filter functionality to my custom collections so that I may perform a for..else loop on the data without accessing the filtered data (so I don't hit 1000 people when the company only has 3 employees), this would do the job. Any ideas?
 
Back
Top