How to handle transactions at Business LogicLayer level

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • psycho

    #1

    How to handle transactions at Business LogicLayer level

    I am working on an N-tier application using following components:
    1. Data Access Layer using DLINQ which consists of Data Context class
    and Table Mapping classes.
    2. Business Logic Layer.
    3. Presentation Layer (normal ASP.NET pages)
    The problem is that I have to handle database transactions which can
    span multiple tables. So where should I place the transaction code. I
    think I should do it in BLL. But how do I control the transaction at
    BLL layer level. Please suggest.

    Thanks in advance.
    - param
  • Andy B

    #2
    Re: How to handle transactions at Business LogicLayer level

    Something that I have always tried to do is create all of the sql
    transactions in the stored procedures of the database and then working with
    the c#/vb code would be a lot easier. You wouldn't have to be always making
    inserts to multiple tables all the time in the application code since thats
    not the applications job anyways. I am just getting into the entity model
    framework and it looks pretty good especially when you can write only 3
    lines of vb code and insert values into about 30 different tables with 100%
    success rate and pretty fast as well. I of course didn't use that in a real
    life application, it was just a junk test that I created to see how much
    entity framework would make my life easier or more complicated.


    "psycho" <paramvir.deol@ gmail.comwrote in message
    news:173168b5-3ffa-4127-9d26-2abf6e590978@f4 0g2000pri.googl egroups.com...
    >I am working on an N-tier application using following components:
    1. Data Access Layer using DLINQ which consists of Data Context class
    and Table Mapping classes.
    2. Business Logic Layer.
    3. Presentation Layer (normal ASP.NET pages)
    The problem is that I have to handle database transactions which can
    span multiple tables. So where should I place the transaction code. I
    think I should do it in BLL. But how do I control the transaction at
    BLL layer level. Please suggest.
    >
    Thanks in advance.
    - param

    Comment

    • sloan

      #3
      Re: How to handle transactions at Business LogicLayer level



      I don't know if there is a right or wrong answer to this....However , I will
      give my opinion.

      First, are you using Sql Server (or another RDBMS)?

      ......

      Option1:
      With Sql Server 2000 and 2005, you can handle multiple table
      transactions inside a usp (user stored procedure). You can accomplish this
      through alot of scalar values OR using XML.
      With 2008, you can accomplish this using
      Browse thousands of hours of video content from Microsoft. On-demand video, certification prep, past Microsoft events, and recurring series.

      Table Valued Parameters. I have experience with 2000/2005 and am only
      getting into 2008 with this particuliar need.
      You would handle the Transactions at the USP level.

      Here is the most basic example of a usp transaction on 2 updates:

      THis isn't a great example, but has the nuts/bolts of the logic.
      Actually, I would use the:
      dbo.uspEmployee DepartmentJobTi tleUpdate
      from the next URL I mention immediately below as an example.

      Option2:
      https://www.microsoft.com/communitie...r=US&sloc=&p=1

      You can put the transaction code in DotNet code. The above link shows some
      examples of that I coded up. I didn't get alot of feedback on the post fyi.
      But at least you have the code examples.
      The example uses 3 tables, Emp, Dept, JobTitle.

      Now, we have to discuss what you mean and I mean by BAL and DAL. Some
      people have the BAL call "Helpers" and consider that the DAL. Example. The
      BAL calling (directly) the SqlHelper class of the DAAB (circa 4-5 years
      ago).

      Some people (like me) have a DAL layer, and uses the SqlHelper or
      EnterpriseLibra ry.Data ~as helpers.....and not "instead of" the DAL.
      You can see a code example of this here:
      http://sholliday.space s.live.com/Blog/cns!A68482B9628 A842A!140.entry
      (Also check my 1.1 version of that same article at
      http://sholliday.spaces.live.com/Blog/ or
      http://sholliday.spaces.live.com/feed.rss )

      If you're using a true DAL (and not simply (and errantly in my opinion)
      calling a Helper class from your BAL).......then you ~can code up the
      transactions in the DAL.

      If I were talking to 2 different databases, I would use this approach. I
      would pick on of the DAL (DotNet) syntaxes from the URL (listed underneath
      of Option2 above) and use that.

      If I were using a non SQL Server RDBMS like Oracle, I would use this
      approach as well...since my experience with Oracle and Xml was not a found
      one.

      ............... ....

      So my nutshell advice:
      1. If you're using Sql Server, I would try XML to pass all your data down
      and use usp's (BEGIN TRAN, COMMIT TRAN, ROLLBACK TRAN). << My opinion.
      2. If you're using multiple databases or something non sql
      server.......th en (A) Make sure you have an actual DAL layer defined (and
      are NOT simply using the "Helper" classes like SqlHelper or
      EnterpriseLibra ry.Data)....... .and then put in DotNet transactions. The URL
      (mentioned above under Option 2) should provide the syntax(es) for that.

      ............... .

      Good luck.





      "psycho" <paramvir.deol@ gmail.comwrote in message
      news:173168b5-3ffa-4127-9d26-2abf6e590978@f4 0g2000pri.googl egroups.com...
      >I am working on an N-tier application using following components:
      1. Data Access Layer using DLINQ which consists of Data Context class
      and Table Mapping classes.
      2. Business Logic Layer.
      3. Presentation Layer (normal ASP.NET pages)
      The problem is that I have to handle database transactions which can
      span multiple tables. So where should I place the transaction code. I
      think I should do it in BLL. But how do I control the transaction at
      BLL layer level. Please suggest.
      >
      Thanks in advance.
      - param

      Comment

      • psycho

        #4
        Re: How to handle transactions at Business LogicLayer level

        I have found a way to manage transactions using TransactionScop e.

        using (TransactionSco pe scope = new TransactionScop e
        (TransactionSco peOption.Requir esNew))
        {
        User.Save();
        UserGroup.Save( );

        scope.Complete( );

        }

        Comment

        Working...