Results 1 to 6 of 6

Thread: [2.0] Transaction/design question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    68

    [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. :-)

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    68

    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.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    68

    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?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    68

    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
  •  



Click Here to Expand Forum to Full Width