C # implements AOP transactions with attributes

Source: Internet
Author: User
Tags aop

C # implements AOP transactions with attributes [C # | AOP | Attribute | ContextAttribute | Icontributeobjectsink | IMessageSink]

Notice before reading

1. The core of the entire article and the breakthrough point is the use of context contexts, it is important to pay attention to the role of CallContext throughout the program

2. The sqlhelper used in this article are Microsoft SqlHelper.cs.

3. This article focuses on how to achieve, and has been tested through, only paste key code, so please read carefully, some of the code directly copied down to run will be wrong!

Body

First, let's look at a piece of code that does not add to the transaction:

SqlDAL.cs

Public abstract class Sqldal {#region ConnectionString private sqlconnectionstringbuilder _connectio
        nstring = null; <summary>///String Connection///</summary> public virtual SqlConnectionStringBuilder Conne ctionstring {get {if (_connectionstring = = NULL | | string. IsNullOrEmpty (_connectionstring.connectionstring)) {_connectionstring = new Sqlconnec
                Tionstringbuilder (configurations.sqlserver_connection_string);
            return _connectionstring;
        set {_connectionstring = value;}
            #endregion #region executenonquery public int ExecuteNonQuery (string cmdtext) {
        Return Sqlhelper.executenonquery (connectionstring.connectionstring, CommandType.Text, Cmdtext); public int ExecuteNonQuery (string cmdtext, CommandType type) {
            Return Sqlhelper.executenonquery (connectionstring.connectionstring, type, cmdtext);
            public int ExecuteNonQuery (string cmdtext, CommandType type, params sqlparameter[] cmdparameters) {
        Return Sqlhelper.executenonquery (connectionstring.connectionstring, type, Cmdtext, cmdparameters); } #endregion

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.