Dapper源碼講解

來源:互聯網
上載者:User

標籤:一個   dapper   alt   blog   產生   返回   int   委託   tca   

Nuget下載dapper的程式集,瀏覽公開的方法,如所示

 

 

 

 

主要講解:Execute方法的調用過程,

public static int Execute(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)

 

此方法代碼:

 

 

內部調用了ExecuteImpl方法

 

 

,數字修正為數組

 

下面講解ExecuteCommand方法

 

 

 

上面的代碼中一共出現兩個類Identity(標識),CacheInfo(緩衝資訊)

 先說Identity這個類,是用來對CommandText,CommandType,cnn,param的一個封裝,用於唯一標識這些對象。為緩衝機制,提供一個唯一標識。

identity = new Identity(command.CommandText, command.CommandType, cnn, null, param.GetType(), null);

 

那麼我們再來看這個類CacheInfo,用identity,param,bool參數來構造。

info = GetCacheInfo(identity, param, command.AddToCache);

 

下面看它的建構函式:

 

 

 

 

 我們接下來,查看步驟3中的圈著的方法,是用來產生一個無傳回值的委託,參數是ICommand和object

 

Dapper源碼講解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.