Add Storageable(List<Dictionary<string,object>> dictionaryList,string tableName)

This commit is contained in:
sunkaixuan 2022-04-30 13:43:16 +08:00
parent e86b83f8a6
commit ee948ce685
4 changed files with 37 additions and 0 deletions

View File

@ -66,6 +66,12 @@ namespace OrmTest
.WhereColumns("id").ToStorage();
x4.AsDeleteable.ExecuteCommand();
var dicList = db.Queryable<Order>().Take(10).ToDictionaryList();
var x5 =
db.Storageable(dicList, "order")
.WhereColumns("id").ToStorage();
x5.AsUpdateable.IgnoreColumns("items").ExecuteCommand();
Console.WriteLine("");
Console.WriteLine("#### Saveable End ####");
}

View File

@ -543,6 +543,30 @@ namespace SqlSugar
#endregion
#region DataTable
public DataTable DictionaryListToDataTable(List<Dictionary<string, object>> list)
{
DataTable result = new DataTable();
if (list.Count == 0)
return result;
var columnNames = list.First();
foreach (var item in columnNames)
{
result.Columns.Add(item.Key,item.Value==null?typeof(object):item.Value.GetType());
}
foreach (var item in list)
{
var row = result.NewRow();
foreach (var key in item.Keys)
{
row[key] = item[key];
}
result.Rows.Add(row);
}
return result;
}
public dynamic DataTableToDynamic(DataTable table)
{
List<Dictionary<string, object>> deserializeObject = new List<Dictionary<string, object>>();

View File

@ -38,5 +38,6 @@ namespace SqlSugar
Task PageEachAsync<T>(IEnumerable<T> pageItems, int pageSize, Func<List<T>, Task> action);
Task PageEachAsync<T, ResultType>(IEnumerable<T> pageItems, int pageSize, Func<List<T>, Task<ResultType>> action);
List<IConditionalModel> JsonToConditionalModels(string json);
DataTable DictionaryListToDataTable(List<Dictionary<string, object>> dictionaryList);
}
}

View File

@ -365,6 +365,12 @@ namespace SqlSugar
{
return this.Context.Storageable(data);
}
public StorageableDataTable Storageable(List<Dictionary<string,object>> dictionaryList,string tableName)
{
DataTable dt = this.Context.Utilities.DictionaryListToDataTable(dictionaryList);
dt.TableName = tableName;
return this.Context.Storageable(dt);
}
public IStorageable<T> Storageable<T>(List<T> dataList) where T : class, new()
{