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