C# Dapper 輕量ORM調試對SQLServer

來源:互聯網
上載者:User

標籤:

Dapper簡介

Dapper只有一個代碼檔案,完全開源,你可以放在項目裡的任何位置,來實現資料到對象的ORM操作,體積小速度快。 使用ORM的好處是增、刪、改很快,不用自己寫sql,因為這都是重複技術含量低的工作,還有就是程式中大量的從資料庫中讀資料然後建立model,並為model欄位賦值。這些ORM都可以輕鬆給你搞定。ORM給我們開發帶來便利時,效能也是一個讓我們不得不考慮的問題。一般的ORM效能和直接寫原生的sql比都差不少,但是Dapper效能還很錯,甚至和DbHelperSQL方式效能高出很多。

假如你喜歡原生的Sql語句,又喜歡ORM的簡單,那你一定會喜歡上Dapper這款ROM。

Dapper

 

Dapper 功能實現

 1 Dapper 功能實現 2 /// <summary> 3         /// 執行sql語句 4         /// </summary> 5         /// <param name="strSql"></param> 6         /// <returns></returns> 7         public int ExecuteBySql(string strSql) 8         { 9             if (dbTransaction == null)10             {11                 using (var connection = Connection)12                 {13                     return connection.Execute(strSql);14                 }15             }16             else17             {18                 dbTransaction.Connection.Execute(strSql, null, dbTransaction);19                 return 0;20 21             }22         }23         /// <summary>24         /// 執行sql語句帶參數的25         /// </summary>26         /// <param name="strSql"></param>27         /// <param name="dbParameter"></param>28         /// <returns></returns>29         public int ExecuteBySql(string strSql, params DbParameter[] dbParameter)30         {31             if (dbTransaction == null)32             {33                 using (var connection = Connection)34                 {35                     return connection.Execute(strSql, dbParameter);36                 }37             }38             else39             {40                 dbTransaction.Connection.Execute(strSql, dbParameter, dbTransaction);41                 return 0;42 43             }44         }45         /// <summary>46         /// 執行預存程序47         /// </summary>48         /// <param name="procName"></param>49         /// <returns></returns>50         public int ExecuteByProc(string procName)51         {52             if (dbTransaction == null)53             {54                 using (var connection = Connection)55                 {56                     return connection.Execute(procName);57                 }58             }59             else60             {61                 dbTransaction.Connection.Execute(procName, null, dbTransaction);62                 return 0;63 64             }65         }66         /// <summary>67         /// 執行預存程序帶參數的68         /// </summary>69         /// <param name="procName"></param>70         /// <param name="dbParameter"></param>71         /// <returns></returns>72         public int ExecuteByProc(string procName, params DbParameter[] dbParameter)73         {74             if (dbTransaction == null)75             {76                 using (var connection = Connection)77                 {78                     return connection.Execute(procName, dbParameter);79                 }80             }81             else82             {83                 dbTransaction.Connection.Execute(procName, dbParameter, dbTransaction);84                 return 0;85 86             }87         }

 

C# Dapper 輕量ORM調試對SQLServer

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.