Implementation of business-layer transactions in csla

Source: Internet
Author: User

In enterprise development, transactions are frequently used to maintain business data consistency.

In the csla framework, some articles say that you only need to add a label ([transactional (transactionaltypes. transactionscope)]) to the method. After a lot of my practices, this label does not work.

We initially used sqltransaction to pass the transaction as a parameter between methods, which produces two problems:

1. The call between business methods occurs in the data access layer Dao, which will inevitably write some business logic in the data access layer, and the business logic layer will lose its due role.

2. transactions are difficult to control and have a large amount of code. When calling other business methods, there may not be transaction parameters.

The solution is to use transactionscope (a transaction of magnitude) in the business logic layer. The method is as follows:

1. Reference System. Transactions. dll in the project

2. Introduce the namespace using system. transactions into the class file;

3. Rewrite the csla method. The Code is as follows:

Save method of resumescore class 1 Public override resumescore save ()
2 {
3 resumescore = NULL;
4 using (transactionscope Ts = new transactionscope (transactionscospontion. Required ))
5 {
6 resumescore = base. Save ();
7 ts. Complete ();
8}
9 return resumescore;
10} Save method of resume class 1 Public override resume save ()
2 {
3 resume = NULL;
4 using (transactionscope Ts = new transactionscope (transactionscospontion. Required ))
5 {
6 resume = base. Save ();
7 if (this. resumescore! = NULL)
8 {
9 This. resumescore. Save ();
10}
11 ts. Complete ();
12}
13 return resume;
14}

In the above Code, the SAVE method of resume calls the Save method of resumescore, so that the business processing is written in the business layer and the transaction processing is realized.

Description, transactionscope instructions and usage, please refer to: http://www.cnblogs.com/zhangpengshou/archive/2009/07/20/1527269.html

Note: You need to start distributed transactions and enable network access, you can view other information, such as http://www.cnblogs.com/dengsu888666/archive/2007/04/02/696555.html

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.