Storing objects added to a collection in a database 
Author Message
 Storing objects added to a collection in a database

I want to add an object to the collection I am building then store that objects properties in a database so I can retrieve that info the next time the class is Initialized.

What is the proper way to do this.

Right now I am doing the following

I have created a Refresh method that Kills the private collection (mCol) then creates a new private collection (mCol),  Adds each object to the collection with it's properties that are stored in the database. I call this method on the Initialize event of the collection.

I don't want to add objects that are already in the database to the database each time the collection is initialized. So it seems to me I have a few options.

1. I can add a boolean Argument to the Add method ie AddToDatabase as Boolean. I don't like this because it exposes that to the outside.

2. I can have a private boolean variable ie Private mvarAddToDatabase  As boolean and set it when I want it to add something to the collection and not to the database. I will have to be careful to make sure this variable is always correct.

3. Check to see if the object is in the database each time the add method is called and add it to the database if it isn't in there. This seems to be more overhead ... If I am pulling the data from the database to fill in the collection I shouldn't have to check to see if that same data is in the database.

What is the best practice for this?


Fri, 02 Dec 2005 23:14:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. ? Collection add object -> usercontrol add control

2. ? Collection add object -> usercontrol add control

3. Adding objects to a collection object

4. destroying objects stored in collections

5. Storing objects in collection/array

6. How to handle events from objects stored in a collection

7. Adding to Collection Object

8. Storing a collection in a collection

9. How do you add object to a collection

10. More on Adding a class object to collections

11. Adding user defined types to a collection object

12. Adding objects to collections


Powered by phpBB® Forum Software