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' });


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM