C # Dapper Lightweight ORM Debugging for SQL Server

Source: Internet
Author: User

Dapper Introduction

Dapper has only one code file, fully open source, you can put in the project anywhere, to achieve data-to-object ORM operation, small volume speed. The advantage of using ORM is to increase, delete, change quickly, do not have to write their own SQL, because this is a repetitive technical content of the work, there is a large number of programs to read from the database and then create model, and assign values to the Model field. These ORM can be easily done for you. When ORM facilitates our development, performance is also a problem that we have to consider. General ORM Performance and direct write native SQL is much worse, but Dapper performance is also very wrong, even and Dbhelpersql mode performance is much higher.

If you like native SQL statements and you like the simplicity of ORM, then you will love the dapper ROM.

Dapper

Dapper function implementation

1 Dapper Function Implementation2 /// <summary>3         ///Execute SQL statement4         /// </summary>5         /// <param name= "strSQL" ></param>6         /// <returns></returns>7          Public intExecutebysql (stringstrSQL)8         {9             if(Dbtransaction = =NULL)Ten             { One                 using(varConnection =Connection) A                 { -                     returnconnection. Execute (strSQL); -                 } the             } -             Else -             { -DbTransaction.Connection.Execute (strSQL,NULL, dbtransaction); +                 return 0; -  +             } A         } at         /// <summary> -         ///executes the SQL statement with the parameter -         /// </summary> -         /// <param name= "strSQL" ></param> -         /// <param name= "DbParameter" ></param> -         /// <returns></returns> in          Public intExecutebysql (stringstrSQL,paramsdbparameter[] dbparameter) -         { to             if(Dbtransaction = =NULL) +             { -                 using(varConnection =Connection) the                 { *                     returnconnection. Execute (strSQL, dbparameter); $                 }Panax Notoginseng             } -             Else the             { + DbTransaction.Connection.Execute (strSQL, DbParameter, dbtransaction); A                 return 0; the  +             } -         } $         /// <summary> $         ///Executing stored procedures -         /// </summary> -         /// <param name= "procname" ></param> the         /// <returns></returns> -          Public intExecutebyproc (stringprocname)Wuyi         { the             if(Dbtransaction = =NULL) -             { Wu                 using(varConnection =Connection) -                 { About                     returnconnection. Execute (procname); $                 } -             } -             Else -             { ADbTransaction.Connection.Execute (ProcName,NULL, dbtransaction); +                 return 0; the  -             } $         } the         /// <summary> the         ///executes a stored procedure with parameters the         /// </summary> the         /// <param name= "procname" ></param> -         /// <param name= "DbParameter" ></param> in         /// <returns></returns> the          Public intExecutebyproc (stringProcName,paramsdbparameter[] dbparameter) the         { About             if(Dbtransaction = =NULL) the             { the                 using(varConnection =Connection) the                 { +                     returnconnection. Execute (procname, dbparameter); -                 } the             }Bayi             Else the             { the DbTransaction.Connection.Execute (procname, DbParameter, dbtransaction); -                 return 0; -  the             } the}

C # Dapper Lightweight ORM Debugging for SQL Server

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.