mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 23:13:42 +08:00
Add ForEachByPageAsync
This commit is contained in:
parent
80ededd501
commit
9897a0e5c5
@ -1477,6 +1477,43 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
totalNumber = count;
|
totalNumber = count;
|
||||||
}
|
}
|
||||||
|
public virtual async Task ForEachByPageAsync(Action<T> action, int pageIndex, int pageSize,RefAsync<int> totalNumber, int singleMaxReads = 300, System.Threading.CancellationTokenSource cancellationTokenSource = null)
|
||||||
|
{
|
||||||
|
int count = this.Clone().Count();
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
if (pageSize > singleMaxReads && count - ((pageIndex - 1) * pageSize) > singleMaxReads)
|
||||||
|
{
|
||||||
|
Int32 Skip = (pageIndex - 1) * pageSize;
|
||||||
|
Int32 NowCount = count - Skip;
|
||||||
|
Int32 number = 0;
|
||||||
|
if (NowCount > pageSize) NowCount = pageSize;
|
||||||
|
while (NowCount > 0)
|
||||||
|
{
|
||||||
|
if (cancellationTokenSource?.IsCancellationRequested == true) return;
|
||||||
|
if (number + singleMaxReads > pageSize) singleMaxReads = NowCount;
|
||||||
|
foreach (var item in await this.Clone().Skip(Skip).Take(singleMaxReads).ToListAsync())
|
||||||
|
{
|
||||||
|
if (cancellationTokenSource?.IsCancellationRequested == true) return;
|
||||||
|
action.Invoke(item);
|
||||||
|
}
|
||||||
|
NowCount -= singleMaxReads;
|
||||||
|
Skip += singleMaxReads;
|
||||||
|
number += singleMaxReads;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (cancellationTokenSource?.IsCancellationRequested == true) return;
|
||||||
|
foreach (var item in this.Clone().ToPageList(pageIndex, pageSize))
|
||||||
|
{
|
||||||
|
if (cancellationTokenSource?.IsCancellationRequested == true) return;
|
||||||
|
action.Invoke(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
totalNumber = count;
|
||||||
|
}
|
||||||
|
|
||||||
public List<T> ToOffsetPage(int pageIndex, int pageSize)
|
public List<T> ToOffsetPage(int pageIndex, int pageSize)
|
||||||
{
|
{
|
||||||
|
@ -111,6 +111,7 @@ namespace SqlSugar
|
|||||||
void ForEach(Action<T> action, int singleMaxReads = 300, System.Threading.CancellationTokenSource cancellationTokenSource = null);
|
void ForEach(Action<T> action, int singleMaxReads = 300, System.Threading.CancellationTokenSource cancellationTokenSource = null);
|
||||||
Task ForEachAsync(Action<T> action, int singleMaxReads = 300, System.Threading.CancellationTokenSource cancellationTokenSource = null);
|
Task ForEachAsync(Action<T> action, int singleMaxReads = 300, System.Threading.CancellationTokenSource cancellationTokenSource = null);
|
||||||
void ForEachByPage(Action<T> action, int pageIndex, int pageSize, ref int totalNumber, int singleMaxReads = 300, System.Threading.CancellationTokenSource cancellationTokenSource = null);
|
void ForEachByPage(Action<T> action, int pageIndex, int pageSize, ref int totalNumber, int singleMaxReads = 300, System.Threading.CancellationTokenSource cancellationTokenSource = null);
|
||||||
|
Task ForEachByPageAsync(Action<T> action, int pageIndex, int pageSize, RefAsync<int> totalNumber, int singleMaxReads = 300, System.Threading.CancellationTokenSource cancellationTokenSource = null);
|
||||||
int Count();
|
int Count();
|
||||||
Task<int> CountAsync();
|
Task<int> CountAsync();
|
||||||
int Count(Expression<Func<T, bool>> expression);
|
int Count(Expression<Func<T, bool>> expression);
|
||||||
|
Loading…
Reference in New Issue
Block a user