diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index ef0477cec..641ea40ed 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -1193,7 +1193,7 @@ namespace SqlSugar } else if (entityType.IsAnonymousType() || isComplexModel) { - result = this.Context.Utilities.DataReaderToDynamicList(dataReader); + result = this.Context.Utilities.DataReaderList(dataReader); } else { diff --git a/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs b/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs index 00e3ad276..5aa89f2d9 100644 --- a/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs +++ b/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs @@ -118,7 +118,7 @@ namespace SqlSugar /// /// /// - public List DataReaderToDynamicList(IDataReader reader) + public List DataReaderList(IDataReader reader) { using (reader) { @@ -305,6 +305,24 @@ namespace SqlSugar return this.DeserializeObject(this.SerializeObject(deserializeObject)); } + public List DataTableToList(DataTable table) + { + List> deserializeObject = new List>(); + Dictionary childRow; + foreach (DataRow row in table.Rows) + { + childRow = new Dictionary(); + foreach (DataColumn col in table.Columns) + { + var addItem = row[col]; + if (addItem == DBNull.Value) + addItem = null; + childRow.Add(col.ColumnName, addItem); + } + deserializeObject.Add(childRow); + } + return this.DeserializeObject>(this.SerializeObject(deserializeObject)); + } #endregion #region Cache diff --git a/Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs b/Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs index 046e58dda..841753bc6 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs @@ -13,7 +13,7 @@ namespace SqlSugar SqlSugarClient Context { get; set; } ExpandoObject DataReaderToExpandoObject(IDataReader reader); List DataReaderToExpandoObjectList(IDataReader reader); - List DataReaderToDynamicList(IDataReader reader); + List DataReaderList(IDataReader reader); string SerializeObject(object value); T DeserializeObject(string value); T TranslateCopy(T sourceObject);