Dofactory.com
Dofactory.com
 Back to list
Views:   8.5K
Replies:  1
Archived

Update Method in the Business Layer

It seems in the project that the BusinessLogic is only relevant in the web application. The MVC application does the dataValidation on the Entity object in the presentation and the Web application does the validation in the BL. Also, the Web application bascially has to to 2 calls to the database for an update for the BL to work? For an update it seems to do another call for a select even though you are doing an update, updates the object with the values and then does a call to the update which then the BL layer does it's validation.

thanks
Dennis
Dennis Tucker, Aug 09, 2011
Reply 1
Dennis:

I think you bring up an interesting question. I myself came from the database world and initially asked the same question.
However, to keep thing uniform and simple, there are only a hand-full of statements that usually are executed against the database.
Usually these are your typical CRUD (CREATE, READ, UPDATE, DELETE) operations: i.e. INSERT record, UPDATE record, DELETE record, and SELECT record.

As you said, with the UPDATE you could only update the columns that were changed. But to keep things relatively simple, usually the entire record, that is, all columns are updated, whether they were changed or not.

For example you may have a page where a USER name is changed, a second page where USER address is changed, and a third page where USER membership options are changed.  If all fields live in the same table, ie. USER, you will see that each of these pages uses the exact same UPDATE statement.   To make this possible you need to retrieve the entire record, before updating.

Indeed, this is redundant but databases are so fast nowadays that it does not really matter.  Also, updates are usually less frequent than SELECTS (or INSERTS most of the time). Now, if performance is extremely critical you could of course write a single, optimized, and lightweight UPDATE statement with only the relevant columns. This requires fine-grained SQL handcoding which is why it is typically not done that way.

Hope this helps.

Dan McMillan, Aug 10, 2011
thanx a lot
Mar 08, 2011
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.