Read/Update one field in a database table

Read/Update one field in a database table

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


reagan123 posted on Saturday, March 28, 2009

I have a situation where I will need to be able to fetch one value from one column in a database.  Sometimes I will need to be able to update this value as well.

I was thinking of using a command object for this?  Does this seem like the appropriate way to handle this?

Also, Would one command object be able to do the update/read or would I need 2?  I'm still grasping how some of this stuff works.

Thanks!

rsbaker0 replied on Saturday, March 28, 2009

CommandBase would work wll for this, but you would probably need 2 classes.

On the other hand, commands and BusinessBase have some interesting behavior in common (Update for a BO is comparable to Execute for a command), so you could also implement a BO for this with a single property corresponding to the column. Now, you can read and update using the same class. Seems like possible overkill, but it's still a pretty simple class.

We're porting a legacy application that has much ad hoc SQL in it to CSLA, and for the initial port we're just translating the SQL directly, so I have CommandBase derived classes that allow fetching arbitrary scalar values from any table as well as executing arbitrary updates. Depending on how many of these cases you have, you might also consider this approach. However, it provides more exposure and opportunity for mischief than I would like.

reagan123 replied on Saturday, March 28, 2009

Thanks for the response.  I was initially thinking that the BusinessBase would have been overkill.  Still not sure which route I want to take.

I think this is an isolated occasion.

Thanks again!

Copyright (c) Marimer LLC