Update db.Utils

This commit is contained in:
610262374@qq.com 2018-11-20 14:46:19 +08:00
parent 19ae5b1845
commit 2862fdb53f
3 changed files with 21 additions and 3 deletions

View File

@ -1193,7 +1193,7 @@ namespace SqlSugar
} }
else if (entityType.IsAnonymousType() || isComplexModel) else if (entityType.IsAnonymousType() || isComplexModel)
{ {
result = this.Context.Utilities.DataReaderToDynamicList<TResult>(dataReader); result = this.Context.Utilities.DataReaderList<TResult>(dataReader);
} }
else else
{ {

View File

@ -118,7 +118,7 @@ namespace SqlSugar
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="reader"></param> /// <param name="reader"></param>
/// <returns></returns> /// <returns></returns>
public List<T> DataReaderToDynamicList<T>(IDataReader reader) public List<T> DataReaderList<T>(IDataReader reader)
{ {
using (reader) using (reader)
{ {
@ -305,6 +305,24 @@ namespace SqlSugar
return this.DeserializeObject<dynamic>(this.SerializeObject(deserializeObject)); return this.DeserializeObject<dynamic>(this.SerializeObject(deserializeObject));
} }
public List<T> DataTableToList<T>(DataTable table)
{
List<Dictionary<string, object>> deserializeObject = new List<Dictionary<string, object>>();
Dictionary<string, object> childRow;
foreach (DataRow row in table.Rows)
{
childRow = new Dictionary<string, object>();
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<List<T>>(this.SerializeObject(deserializeObject));
}
#endregion #endregion
#region Cache #region Cache

View File

@ -13,7 +13,7 @@ namespace SqlSugar
SqlSugarClient Context { get; set; } SqlSugarClient Context { get; set; }
ExpandoObject DataReaderToExpandoObject(IDataReader reader); ExpandoObject DataReaderToExpandoObject(IDataReader reader);
List<ExpandoObject> DataReaderToExpandoObjectList(IDataReader reader); List<ExpandoObject> DataReaderToExpandoObjectList(IDataReader reader);
List<T> DataReaderToDynamicList<T>(IDataReader reader); List<T> DataReaderList<T>(IDataReader reader);
string SerializeObject(object value); string SerializeObject(object value);
T DeserializeObject<T>(string value); T DeserializeObject<T>(string value);
T TranslateCopy<T>(T sourceObject); T TranslateCopy<T>(T sourceObject);