zoukankan      html  css  js  c++  java
  • dapper的一个小扩展以支持dataset

    废话不多,直接上方法

     1         public static DataSet ExecuteDataSet(this IDbConnection cnn, IDbDataAdapter adapter, string sql, object param = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null)
     2         {
     3             var ds = new DataSet();
     4             var command = new CommandDefinition(sql, (object)param, null, commandTimeout, commandType, buffered ? CommandFlags.Buffered : CommandFlags.None);
     5             var identity = new Identity(command.CommandText, command.CommandType, cnn, null, param == null ? null : param.GetType(), null);
     6             var info = GetCacheInfo(identity, param, command.AddToCache);
     7             bool wasClosed = cnn.State == ConnectionState.Closed;
     8             if (wasClosed) cnn.Open();
     9             adapter.SelectCommand = command.SetupCommand(cnn, info.ParamReader);
    10             adapter.Fill(ds);
    11             if (wasClosed) cnn.Close();
    12             return ds;
    13         }

    在Query方法下面添加即可

    使用Demo

    var mysqlDs = con.ExecuteDataSet(new MySqlDataAdapter(), "SELECT * FROM wjf_role_relation where ROLE_ID=@ROLE_ID", new { ROLE_ID = '1' });

    后台兼职接单中,联系我微信:wjf88520

    by wujf

    mail:921252375@qq.com

  • 相关阅读:
    QButton
    注入
    SpringBoot热重启配置
    centos7 安装 tomcat
    centos 安装jdk
    spring boot (6) AOP的使用
    spring boot (5) 自定义配置
    spring boot (4) 使用log4 打印日志
    SpringBoot (3)设置支持跨域请求
    spring boot (2) 配置swagger2核心配置 docket
  • 原文地址:https://www.cnblogs.com/wujf/p/dapper.html
Copyright © 2011-2022 走看看