BO Design based on using a CheckBoxList Control

BO Design based on using a CheckBoxList Control

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


mtavares posted on Saturday, June 24, 2006

I'm kind of at a quandry in converting a page in my web app that uses a checkboxlist.  Basically each checkbox represents a separate record in the database.  I'm just not sure what the best way to design my business object to work using this control because it databinds to a lookup but there isn't a way to actually bind the selected values directly to a datasource when saving. 

What I'm looking to do from a DB perspective is to delete all records in the backend table, and then add a new record for each selected item in the checkboxlist.

My question is, would it be better to use an editablerootcollection to bind the the checkboxlist and then hack up the dataportal_delete so that it deletes all records and then just insert a new item in the collection for each selected item in the checkboxlist?  However this way I'm not sure how to make it transactional, so the roll back puts back all deleted items if there is a problem

Or, should I use a readOnlyCollection to bind to the checkboxlist, and just use a CommandBase object to perform the Delete and Insert of the selected items at once?

Or am I totally off base and should go another route.

Any guidance would be appreciated.

Thanks,
Mike

RockfordLhotka replied on Tuesday, June 27, 2006

If you are displaying editable data in a list, then using an editable root collection sounds right. Of course it would be a collection of BusinessBase-derived objects that would have one boolean read-write property and then read-only properties for display to the user - so it would be a pretty trivial object on the whole.

But I think you are over-complicating the data access. BusinessListBase-derived objects only implement DataPortal_Update(), and in that method you are responsible for processing all child objects in some manner. It seems like it would be easy enough to loop through the child objects to build your database query such that you could delete all the selected items in a single database call.

Your idea about using a Command object is also quite workable, and in some ways could be more efficient, because it wouldn't necessitate sending the child objects from the collection back to the server (since most of their data is read-only anyway). Your ReadOnlyListBase-derived root object could have a Save() method (of your design) that builds the Command object and executes it.

On the whole, I think I'd opt for a combination of the two Smile [:)]  Use a root BLB, containing BB children. Then override the collection's Save() method to send a Command object to the server to do the actual work. That is the best overall use of the various base classes at your disposal.

Copyright (c) Marimer LLC