码迷,mamicode.com
首页 > 移动开发 > 详细

Dapper源码讲解

时间:2017-06-22 00:08:05      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:一个   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源码讲解

标签:一个   dapper   alt   blog   生成   返回   int   委托   tca   

原文地址:http://www.cnblogs.com/suzixuan/p/7061977.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!