Multiple objects, single transaction. N-Tier

Multiple objects, single transaction. N-Tier

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


martin_s posted on Saturday, April 25, 2009

In the scenario of a client/application server with WCF communications.  The client application makes changes to multiple objects, some of which are not related in a parent/child relationship.  Is it possible to serialize all the objects, dispatch them to the server to be updated in a single database transaction, or can only objects with relationships be included in a transaction.

If this is explained in the C# 2008 book feel free to direct me to the appropriate chapter.

Thanks.
Martin.

DocJames replied on Saturday, April 25, 2009


Hello,

You can take a look at this Wiki entry here:

http://www.lhotka.net/cslanet/faq/(S(rm1rki45kyfvdk55hcxgjoj5))/SaveMultipleRootObjects.ashx

Jimmy

martin_s replied on Saturday, April 25, 2009

Excellent - that clears up a big question mark for me :)

Thank you.

rsbaker0 replied on Saturday, April 25, 2009

I suppose that's one way to do it, but it seems to require you to compose your objects in a way that matches the transaction you want to do.

We don't use the TransactionScope attribute but instead manage our transactions manually, with all saving taking place using a "TransactionContext" class  passed around as a parameter. (Server side of data portal only)

So, while the client calls Save(), this ends up in an Update(TransactionContext) method server side.

All of our BO's implement Update(TransactionContext), so it is possible to execute arbitrary compositions of object updates server side in the same transaction without any change in the object design.

martin_s replied on Sunday, April 26, 2009

I can see how the TransactionContext would work, but how do you transport multiple root objects from client to server in a single network trip ?

Also, can I just ask about generating update statements.  In our current Delphi OPF we have a data access layer which constructs the update SQL containing only the property values which have changed since the load.  Is this something that people have implemented.

rsbaker0 replied on Sunday, April 26, 2009

In our case, what typically happens is that the server-side Update() method may either create or fetch and then update other "root" BO's during the server side processing.

If they need to be fetched client side and transported over, then they indeed need to be part of the object graph as suggested in the FAQ.

Copyright (c) Marimer LLC