From e161cd4e17abaa8050140452e31392e4e5c8f0e7 Mon Sep 17 00:00:00 2001 From: zqlovejyc <943620963@qq.com> Date: Thu, 27 Sep 2018 10:50:06 +0800 Subject: [PATCH] =?UTF-8?q?IDataReader=E6=96=B0=E5=A2=9E=E6=89=A9=E5=B1=95?= =?UTF-8?q?=E6=96=B9=E6=B3=95ToDataSet=E5=92=8CToDynamics=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SQLBuilder.Core/Extensions.cs | 68 ++++++++++++++++++++++++++ SQLBuilder.Core/SQLBuilder.Core.csproj | 10 ++-- 2 files changed, 73 insertions(+), 5 deletions(-) diff --git a/SQLBuilder.Core/Extensions.cs b/SQLBuilder.Core/Extensions.cs index 0c1f25b..9038c34 100644 --- a/SQLBuilder.Core/Extensions.cs +++ b/SQLBuilder.Core/Extensions.cs @@ -623,6 +623,43 @@ public static DataTable ToDataTable(this List @this) } #endregion + #region ToDataSet + /// + /// IDataReader转换为DataSet + /// + /// reader数据源 + /// DataSet + public static DataSet ToDataSet(this IDataReader @this) + { + var ds = new DataSet(); + if (@this.IsClosed == false) + { + do + { + var schemaTable = @this.GetSchemaTable(); + var dt = new DataTable(); + for (var i = 0; i < schemaTable.Rows.Count; i++) + { + var row = schemaTable.Rows[i]; + dt.Columns.Add(new DataColumn((string)row["ColumnName"], (Type)row["DataType"])); + } + while (@this.Read()) + { + var dataRow = dt.NewRow(); + for (var i = 0; i < @this.FieldCount; i++) + { + dataRow[i] = @this.GetValue(i); + } + dt.Rows.Add(dataRow); + } + ds.Tables.Add(dt); + } + while (@this.NextResult()); + } + return ds; + } + #endregion + #region ToDynamic /// /// IDataReader数据转为dynamic对象 @@ -657,6 +694,37 @@ public static IEnumerable ToDynamics(this IDataReader @this) } } } + + /// + /// IDataReader数据转为List<dynamic>集合的集合 + /// + /// IDataReader数据源 + /// List<dynamic>集合的集合 + public static List> ToListDynamics(this IDataReader @this) + { + var result = new List>(); + if (@this?.IsClosed == false) + { + using (@this) + { + do + { + var list = new List(); + while (@this.Read()) + { + var row = new ExpandoObject() as IDictionary; + for (var i = 0; i < @this.FieldCount; i++) + { + row.Add(@this.GetName(i), @this.GetValue(i)); + } + list.Add(row); + } + result.Add(list); + } while (@this.NextResult()); + } + } + return result; + } #endregion #region ToDictionary diff --git a/SQLBuilder.Core/SQLBuilder.Core.csproj b/SQLBuilder.Core/SQLBuilder.Core.csproj index 2167d11..be4d43e 100644 --- a/SQLBuilder.Core/SQLBuilder.Core.csproj +++ b/SQLBuilder.Core/SQLBuilder.Core.csproj @@ -2,18 +2,18 @@ netstandard2.0 - 1.0.1.9 + 1.0.2.0 张强 - 1.0.1.9 + 1.0.2.0 true Expression表达式转换为SQL语句,支持SqlServer、MySQL、Oracle、SQLite、PostgreSQL Copyright © 2018 , 张强 943620963@qq.com https://zqlovejyc.gitee.io/zqutils-js/Images/SQL.png Zq.SQLBuilder.Core - 1.更新Npgsql版本; + 1.修复OracleRepository仓储FindListAsync方法sql拼写错误; -2.修复仓储Update一个重载方法BUG; - 1.0.1.9 +2.IDataReader新增扩展方法ToDataSet和ToListDynamics; + 1.0.2.0