30 lines
960 B
C#
30 lines
960 B
C#
using System.Linq.Expressions;
|
|
|
|
namespace YLErp.Modules.TradeModule.QueryModule
|
|
{
|
|
public class BatchGetTradeRelationDataService<T> where T : DBModelBase
|
|
{
|
|
public List<T> GetListByWhere(Expression<Func<T, bool>> expression, DbSet<T> dataSet, int batchSize = 500)
|
|
{
|
|
var result = new List<T>();
|
|
var newExpression = expression;
|
|
while (true)
|
|
{
|
|
var list = dataSet.AsNoTracking().Where(newExpression).OrderBy(p => p.id).Take(batchSize).ToList();
|
|
if (list != null && list.Count > 0)
|
|
{
|
|
result.AddRange(list);
|
|
}
|
|
if (list == null || list.Count < batchSize)
|
|
{
|
|
break;
|
|
}
|
|
var maxId = list.Max(p => p.id);
|
|
newExpression = expression.And(p => p.id > maxId);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
}
|
|
}
|