|
-
Oct 31st, 2006, 04:19 AM
#1
Thread Starter
Lively Member
[2.0] Transaction/design question
Hi,
I've got a app layer that feeds a 'Country' object to by business layer.
A country object consists of some values and a collection of Region objects.
A region object consists of some values and a collection of City objects.
A city object only consists of some values.
In my business layer I would disassemble the country object and pass all the information to my data layer, where I use 3 methods:
AddCountry(...);
AddRegion(...);
AddCity(...);
Now, I'd like to use transactions so either ALL the information is inserted in the sql server db or NONE.
My question, how would I implement this?
I suppose I can't use transaction stuff in my business layer, but I wouldn't know how I'd use transactions in my DAL since the inserts are seperated between 3 methods.
Maybe I'm doing this all wrong, I don't know. But any feedback would be appreciated. :-)
-
Oct 31st, 2006, 05:59 AM
#2
Thread Starter
Lively Member
Re: [2.0] Transaction/design question
Another question:
The Country object would also be passed to a webservice.
Since it is a custom object with collections of other custom objects, I suppose it can be quite an annoyance.
Is there any way to pass custom objects to a webservice without rewriting your proxy class or whatever?
The 'solutions' I found seemed complex for such a simple task.
-
Oct 31st, 2006, 07:50 PM
#3
Re: [2.0] Transaction/design question
You simply create an ambient transaction in the method that calls the three separate methods. .NET 2.0 support for transactions is much better than previous versions. Read about the TransactionScope class. Basically you create a TransactionScope object and all operations that can enlist in a transaction will do so automatically. You don't need any explicit commands to have each Update enlisted in the same transaction. You need the Distributed Transaction Coordinator service running as that's what does the work.
-
Nov 2nd, 2006, 02:51 AM
#4
Thread Starter
Lively Member
Re: [2.0] Transaction/design question
"in the method that calls the three separate methods".
So in the business layer?
Shouldn't I keep the BL free of any DB related code?
-
Nov 2nd, 2006, 03:23 AM
#5
Re: [2.0] Transaction/design question
An ambient transaction isn't specifically DB-related. The TransactionScope class is member of the System.Transactions namespace so it is not specifically related to ADO.NET, which is all in the System.Data namespace. I'm fairly certain that that's where it will be most used but there is no specific relationship. Given that operations other than data access can be enlisted in an ambient transaction, outside the DAL is absolutely the appropriate place to create one. The BL is the one saying that these operations should be grouped so the BL is the one that should group them.
-
Nov 2nd, 2006, 04:27 AM
#6
Thread Starter
Lively Member
Re: [2.0] Transaction/design question
Alright, thanks.
Any ideas on the Webservice problem anyone?
Haven't found a solution yet.
edit:
And as always, I'd give you posrep if only the system allowed me to.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|