Browse Source

Update db.Inserable.UseParameter

pull/6/head
sunkaixuna 3 years ago
parent
commit
74bd920981
  1. 8
      Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/ParameterInsertable.cs
  2. 13
      Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs
  3. 1
      Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs

8
Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/ParameterInsertable.cs

@ -34,12 +34,13 @@ namespace SqlSugar
}
public async Task<int> ExecuteCommandAsync()
{
int result = 0;
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 =>
await this.Context.Utilities.PageEachAsync<T,int>(objects, 60,async pagelist =>
{
foreach (var item in pagelist)
{
@ -49,9 +50,10 @@ namespace SqlSugar
(itemable as InsertableProvider<T>).RemoveCacheFunc = removeCacheFunc;
itemable.AddQueue();
}
return this.Context.SaveQueuesAsync(false);
result+= await this.Context.SaveQueuesAsync(false);
return result;
});
return objects.Length;
return result;
}
}
}

13
Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs

@ -652,6 +652,19 @@ namespace SqlSugar
}
}
}
public async Task PageEachAsync<T, ResultType>(IEnumerable<T> pageItems, int pageSize, Func<List<T>, Task<ResultType>> 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
}
}

1
Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs

@ -36,5 +36,6 @@ namespace SqlSugar
void RemoveCache<T>(string key);
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);
Task PageEachAsync<T, ResultType>(IEnumerable<T> pageItems, int pageSize, Func<List<T>, Task<ResultType>> action);
}
}

Loading…
Cancel
Save