Browse Source

Update db.Utils

pull/12/MERGE
610262374@qq.com 6 years ago
parent
commit
2862fdb53f
  1. 2
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  2. 20
      Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs
  3. 2
      Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs

2
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

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

20
Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs

@ -118,7 +118,7 @@ namespace SqlSugar
/// <typeparam name="T"></typeparam>
/// <param name="reader"></param>
/// <returns></returns>
public List<T> DataReaderToDynamicList<T>(IDataReader reader)
public List<T> DataReaderList<T>(IDataReader reader)
{
using (reader)
{
@ -305,6 +305,24 @@ namespace SqlSugar
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
#region Cache

2
Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs

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

Loading…
Cancel
Save