mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-01-26 21:38:32 +08:00
Update inserable.UseParameter
This commit is contained in:
@@ -32,5 +32,26 @@ namespace SqlSugar
|
|||||||
});
|
});
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
public async Task<int> ExecuteCommandAsync()
|
||||||
|
{
|
||||||
|
var inserable = Inserable as InsertableProvider<T>;
|
||||||
|
var columns = inserable.InsertBuilder.DbColumnInfoList.GroupBy(it => it.DbColumnName).Select(it => it.Key).Distinct().ToList();
|
||||||
|
var tableWithString = inserable.InsertBuilder.TableWithString;
|
||||||
|
var removeCacheFunc = inserable.RemoveCacheFunc;
|
||||||
|
var objects = inserable.InsertObjs;
|
||||||
|
await this.Context.Utilities.PageEachAsync(objects, 60, pagelist =>
|
||||||
|
{
|
||||||
|
foreach (var item in pagelist)
|
||||||
|
{
|
||||||
|
var itemable = this.Context.Insertable(item);
|
||||||
|
itemable.InsertBuilder.DbColumnInfoList = itemable.InsertBuilder.DbColumnInfoList.Where(it => columns.Contains(it.DbColumnName)).ToList();
|
||||||
|
itemable.InsertBuilder.TableWithString = tableWithString;
|
||||||
|
(itemable as InsertableProvider<T>).RemoveCacheFunc = removeCacheFunc;
|
||||||
|
itemable.AddQueue();
|
||||||
|
}
|
||||||
|
return this.Context.SaveQueuesAsync(false);
|
||||||
|
});
|
||||||
|
return objects.Length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -638,6 +638,20 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task PageEachAsync<T>(IEnumerable<T> pageItems, int pageSize, Func<List<T>,Task> action)
|
||||||
|
{
|
||||||
|
if (pageItems != null && pageItems.Any())
|
||||||
|
{
|
||||||
|
int totalRecord = pageItems.Count();
|
||||||
|
int pageCount = (totalRecord + pageSize - 1) / pageSize;
|
||||||
|
for (int i = 1; i <= pageCount; i++)
|
||||||
|
{
|
||||||
|
var list = pageItems.Skip((i - 1) * pageSize).Take(pageSize).ToList();
|
||||||
|
await action(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,5 +35,6 @@ namespace SqlSugar
|
|||||||
void RemoveCacheAll<T>();
|
void RemoveCacheAll<T>();
|
||||||
void RemoveCache<T>(string key);
|
void RemoveCache<T>(string key);
|
||||||
void PageEach<T>(IEnumerable<T> pageItems, int pageSize, Action<List<T>> action);
|
void PageEach<T>(IEnumerable<T> pageItems, int pageSize, Action<List<T>> action);
|
||||||
|
Task PageEachAsync<T>(IEnumerable<T> pageItems, int pageSize, Func<List<T>, Task> action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
namespace SqlSugar
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
public interface IParameterInsertable<T>
|
public interface IParameterInsertable<T>
|
||||||
{
|
{
|
||||||
int ExecuteCommand();
|
int ExecuteCommand();
|
||||||
|
Task<int> ExecuteCommandAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user