mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 02:29:39 +08:00
Add db.Utils.DataTableToDictionaryList
This commit is contained in:
@@ -572,6 +572,29 @@ namespace SqlSugar
|
|||||||
return table.Rows.Cast<DataRow>().ToDictionary(x => x[0].ToString(), x => x[1]);
|
return table.Rows.Cast<DataRow>().ToDictionary(x => x[0].ToString(), x => x[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Dictionary<string, object>> DataTableToDictionaryList(DataTable dt)
|
||||||
|
{
|
||||||
|
List<Dictionary<string, object>> result = new List<Dictionary<string, object>>();
|
||||||
|
if (dt != null && dt.Rows.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (DataRow dr in dt.Rows)
|
||||||
|
{
|
||||||
|
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||||
|
for (int i = 0; i < dr.Table.Columns.Count; i++)
|
||||||
|
{
|
||||||
|
var value = dr[dr.Table.Columns[i].ColumnName];
|
||||||
|
if (value == DBNull.Value)
|
||||||
|
{
|
||||||
|
value = null;
|
||||||
|
}
|
||||||
|
dic.Add(dr.Table.Columns[i].ColumnName.ToString(), value);
|
||||||
|
}
|
||||||
|
result.Add(dic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Cache
|
#region Cache
|
||||||
|
@@ -29,6 +29,7 @@ namespace SqlSugar
|
|||||||
List<T> DataTableToList<T>(DataTable table);
|
List<T> DataTableToList<T>(DataTable table);
|
||||||
DataTable ListToDataTable<T>(List<T> list);
|
DataTable ListToDataTable<T>(List<T> list);
|
||||||
Dictionary<string, object> DataTableToDictionary(DataTable table);
|
Dictionary<string, object> DataTableToDictionary(DataTable table);
|
||||||
|
List<Dictionary<string, object>> DataTableToDictionaryList(DataTable table);
|
||||||
ICacheService GetReflectionInoCacheInstance();
|
ICacheService GetReflectionInoCacheInstance();
|
||||||
void RemoveCacheAll();
|
void RemoveCacheAll();
|
||||||
void RemoveCacheAll<T>();
|
void RemoveCacheAll<T>();
|
||||||
|
Reference in New Issue
Block a user