mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-04 20:57:58 +08:00
Add Queryable.ForEachByPage
This commit is contained in:
parent
4f61d7e03b
commit
69fdb55f06
@ -1293,6 +1293,44 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public virtual void ForEachByPage(Action<T> action, int pageIndex, int pageSize, ref 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 this.Clone().Skip(Skip).Take(singleMaxReads).ToList())
|
||||||
|
{
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
if (this.Context.CurrentConnectionConfig.DbType != DbType.SqlServer)
|
if (this.Context.CurrentConnectionConfig.DbType != DbType.SqlServer)
|
||||||
|
@ -109,7 +109,7 @@ namespace SqlSugar
|
|||||||
ISugarQueryable<T> Select(string select);
|
ISugarQueryable<T> Select(string select);
|
||||||
ISugarQueryable<T> MergeTable();
|
ISugarQueryable<T> MergeTable();
|
||||||
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);
|
||||||
|
void ForEachByPage(Action<T> action, int pageIndex, int pageSize, ref 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