Database Round Trip -- Is My assumption Correct --

Database Round Trip -- Is My assumption Correct --

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


st3fanus posted on Wednesday, January 13, 2010

Hello..
I'm newbie in Csla..

I want to share and hope any feeback from everyone about my decision , is it correct or there is another better ways to doing my decision... I'll tell my stories below :

I have designed
One RootEditableObject (REO) that have one ChildCollectionObject (CCO) which has a lot of ChildObject (CO).

For example there is a scenario I have fetch my REO from DB and then I've manipulated my REO include several CO (like Delete, update, create new ) inside CCO.. After I have finished I want to save to DB again...

What I have done (my decision now ) Is :
I have create data portal fetch, insert, update in ChildObject class..
So if i have manipulated 5 CO Then my application will called associated dataportal fetch, insert, update 5 times with 5 round trip from my app <----> DB.

Is my design is a good way..?  or there is another option to doing this job..

Thanks for all respond about this posting..

Stefanus




RockfordLhotka replied on Wednesday, January 13, 2010

What you are describing is, to be honest, absolutely incorrect and is completely against the way CSLA is designed to work.

You should read Chapters 1-5 of Expert 2008 Business Objects, and probably chapters 17-18 as well. They will help you understand how to use the framework effectively.

Or get the Core 3.8 video series, as it also walks through exactly how to implement this sort of object model.

CSLA is designed to have a single "root" object that is retrieved/saved through the data portal. Child objects contained in that root object flow through the data portal along with that root object. In your example, you should make exactly 2 calls to the data portal - one to retrieve the object graph, one to save the object graph.

How you talk to your database is a different matter. There are many technologies in .NET to talk to the database (ADO.NET, DataTable, Entity Framework, etc). In most cases, when doing insert/update/delete operations each object will talk to the database on its own - but this is often occurring from an application server sitting in the same data center as the database server, so performance is not a big issue.

Also consider that most app architectures follow this model of having a separate SQL call per object/entity/row/whatever. CSLA is far from unique in supporting this model - and CSLA certainly doesn't require this model. If you'd rather do a batch SQL update, and then reconcile the results you get back from the SQL insert/update/delete operations to update your object graph, then you can certainly do that - but it is a lot of work, which is why it is rarely done (in CSLA or elsewhere).

st3fanus replied on Wednesday, January 13, 2010

Hi  Rock..

I'm very appreciate about your respond...
Sorry.. could you give me a confirmation about this :
Technology that I have chosen is ADO.NET

What do you mean at last paragraph .. ? Is it common to run sql ( insert , update , delete )  inside a store procedure where each calling I have put on Child_Insert, Child_Update, Child_Delete ?

So, For example when I was running FieldManager.UpdateChildren() method inside DataPortal_Insert Inside UpdateChildren() method will loop for each Child Object to Run appropriate Child_Insert, Child_Update, Child_Delete to run each sql I've describe above...

Thank A lot before about your respond..

GBU

RockfordLhotka replied on Thursday, January 14, 2010

Well think about a list of child items. You could implement the list's data access code to loop through and find all changed child items. Using that information you could create one large SQL command, with a SQL INSERT/UPDATE/DELETE for each changed row - all concatinated into this one SQL command. And you could execute that command - thus making one database call to do all the changes.

That's not too hard.

But now suppose that the INSERT items generate new unique key values. And suppose the INSERT/UPDATE items generate new timestamp values. How do you get all those values back? And when you get them back, how do you find the appropriate objects in your list so you can update the objects with the new id/timestamp values?

This can be done, but it is not too easy.

st3fanus replied on Thursday, January 14, 2010

Hi Rock.. Thanks a lot..

So.. Which is the way where CSLA is created for ? Use several call in each child OR Use one large SQL command for several child ?

I really hope you're not boring with my question rock :)
And what is different of Book 2008 Businees Object with Video Core 3.8 as you said before ?


Thanks a lot..


Stefanus
God Bless You

RockfordLhotka replied on Thursday, January 14, 2010

CSLA doesn't do your data access, and so you can choose either implementation.

Most people have each object save itself to the database because that is a LOT easier.

Regarding the book and videos, the Expert 2008 Business Objects book is half about how to use CSLA and half about how CSLA itself is implemented. The video series is 100% about how to use CSLA. The book is about version 3.6, and the videos are about 3.8, so the videos are more current than the book.

Both are valuable. Some people learn better by reading, others by listening or watching.

st3fanus replied on Friday, January 15, 2010

Thanks a lot about your respond rock..
I'm very appreciate it.


GBU


st3fanus replied on Friday, January 15, 2010

Hi Rock..

I forgot to ask you about : How much the video series ..?

GBU

stefanus

RockfordLhotka replied on Friday, January 15, 2010

st3fanus:
Hi Rock..

I forgot to ask you about : How much the video series ..?

http://store.lhotka.net/

Copyright (c) Marimer LLC