mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-18 17:48:11 +08:00
Update Storageable
This commit is contained in:
@@ -40,6 +40,21 @@ namespace OrmTest
|
|||||||
var x2 = db.Storageable<Order>(new Order() { Id = 0, Name = "jack" }).ToStorage();
|
var x2 = db.Storageable<Order>(new Order() { Id = 0, Name = "jack" }).ToStorage();
|
||||||
x2.BulkCopy();
|
x2.BulkCopy();
|
||||||
x2.BulkUpdate();
|
x2.BulkUpdate();
|
||||||
|
|
||||||
|
var dt = db.Queryable<Order>().ToDataTable();
|
||||||
|
dt.TableName = "order";
|
||||||
|
var addRow = dt.NewRow();
|
||||||
|
addRow["id"] = 0;
|
||||||
|
addRow["price"] = 1;
|
||||||
|
addRow["Name"] = "a";
|
||||||
|
dt.Rows.Add(addRow);
|
||||||
|
var x3 =
|
||||||
|
db.Storageable(dt)
|
||||||
|
.WhereColumns("id").ToStorage();
|
||||||
|
|
||||||
|
x3.AsInsertable.IgnoreColumns("id").ExecuteCommand();
|
||||||
|
x3.AsUpdateable.ExecuteCommand();
|
||||||
|
|
||||||
Console.WriteLine("");
|
Console.WriteLine("");
|
||||||
Console.WriteLine("#### Saveable End ####");
|
Console.WriteLine("#### Saveable End ####");
|
||||||
}
|
}
|
||||||
|
@@ -60,7 +60,7 @@ namespace SqlSugar
|
|||||||
public StorageableDataTable Saveable(string inserMessage = null, string updateMessage = null)
|
public StorageableDataTable Saveable(string inserMessage = null, string updateMessage = null)
|
||||||
{
|
{
|
||||||
SplitUpdate(it => it.Any(), updateMessage);
|
SplitUpdate(it => it.Any(), updateMessage);
|
||||||
SplitInsert(it => it.Any(), inserMessage);
|
SplitInsert(it => true, inserMessage);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public StorageableDataTable SplitError(Func<DataRow, bool> conditions, string message = null)
|
public StorageableDataTable SplitError(Func<DataRow, bool> conditions, string message = null)
|
||||||
@@ -76,6 +76,10 @@ namespace SqlSugar
|
|||||||
|
|
||||||
public DataTableResult ToStorage()
|
public DataTableResult ToStorage()
|
||||||
{
|
{
|
||||||
|
if (whereFuncs == null || whereFuncs.Count == 0)
|
||||||
|
{
|
||||||
|
Saveable();
|
||||||
|
}
|
||||||
foreach (DataRow row in DataTable.Rows)
|
foreach (DataRow row in DataTable.Rows)
|
||||||
{
|
{
|
||||||
foreach (var item in whereFuncs.OrderByDescending(it => (int)it.key))
|
foreach (var item in whereFuncs.OrderByDescending(it => (int)it.key))
|
||||||
@@ -90,12 +94,39 @@ namespace SqlSugar
|
|||||||
.ToList();
|
.ToList();
|
||||||
DataTable.Columns.Remove(SugarGroupId);
|
DataTable.Columns.Remove(SugarGroupId);
|
||||||
DataTable.Columns.Remove(SugarErrorMessage);
|
DataTable.Columns.Remove(SugarErrorMessage);
|
||||||
|
var inserList = new List<Dictionary<string, object>>();
|
||||||
|
var updateList = new List<Dictionary<string, object>>();
|
||||||
|
if (Groups.Any(it => it.Type == StorageType.Insert.ToString()))
|
||||||
|
{
|
||||||
|
foreach (var item in Groups)
|
||||||
|
{
|
||||||
|
if (item.Type == StorageType.Insert.ToString())
|
||||||
|
{
|
||||||
|
item.DataTable.Columns.Remove(SugarGroupId);
|
||||||
|
item.DataTable.Columns.Remove(SugarErrorMessage);
|
||||||
|
inserList.AddRange(this.Context.Utilities.DataTableToDictionaryList(item.DataTable));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Groups.Any(it => it.Type == StorageType.Update.ToString()))
|
||||||
|
{
|
||||||
|
foreach (var item in Groups)
|
||||||
|
{
|
||||||
|
if (item.Type == StorageType.Update.ToString())
|
||||||
|
{
|
||||||
|
item.DataTable.Columns.Remove(SugarGroupId);
|
||||||
|
item.DataTable.Columns.Remove(SugarErrorMessage);
|
||||||
|
updateList.AddRange(this.Context.Utilities.DataTableToDictionaryList(item.DataTable));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var tableName = this.Context.Queryable<object>().SqlBuilder.GetTranslationTableName(DataTable.TableName);
|
||||||
DataTableResult result = new DataTableResult()
|
DataTableResult result = new DataTableResult()
|
||||||
{
|
{
|
||||||
DataTableGroups=Groups,
|
DataTableGroups=Groups,
|
||||||
AsDeleteable=this.Context.Deleteable<object>().AS(DataTable.TableName).Where(""),
|
AsDeleteable=this.Context.Deleteable<object>().AS(tableName).Where(""),
|
||||||
AsUpdateable= this.Context.Updateable(new List<Dictionary<string,object>>()).AS(DataTable.TableName).WhereColumns(Columns),
|
AsUpdateable= this.Context.Updateable(updateList).AS(tableName).WhereColumns(Columns),
|
||||||
AsInsertable=this.Context.Insertable(new List<Dictionary<string, object>>()).AS(DataTable.TableName)
|
AsInsertable=this.Context.Insertable(inserList).AS(tableName)
|
||||||
};
|
};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user