mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Add db.Utils.DataTableToDictionaryList
This commit is contained in:
parent
13e8ebeab9
commit
069f2f8267
@ -572,6 +572,29 @@ namespace SqlSugar
|
||||
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
|
||||
|
||||
#region Cache
|
||||
|
@ -29,6 +29,7 @@ namespace SqlSugar
|
||||
List<T> DataTableToList<T>(DataTable table);
|
||||
DataTable ListToDataTable<T>(List<T> list);
|
||||
Dictionary<string, object> DataTableToDictionary(DataTable table);
|
||||
List<Dictionary<string, object>> DataTableToDictionaryList(DataTable table);
|
||||
ICacheService GetReflectionInoCacheInstance();
|
||||
void RemoveCacheAll();
|
||||
void RemoveCacheAll<T>();
|
||||
|
Loading…
Reference in New Issue
Block a user