• Dapper源码讲解


    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

  • 相关阅读:
    学习进度(第十四周)
    学习进度(第十三周)
    程序员修炼之道阅读笔记03
    程序员修炼之道阅读笔记02
    学习进度(第十二周)
    冲刺进度条10
    冲刺进度条09
    冲刺进度条08
    寒假学习进度报告2
    寒假学习进度报告1
  • 原文地址:https://www.cnblogs.com/suzixuan/p/7061977.html
Copyright © 2020-2023  润新知