假设我有这个属性:
private Response1 _response;
private int _pageNumber = 0;
private int _pageSize = 1000;
这是我的回答:
_response = await Find(_pageNumber, _pageSize, "").ConfigureAwait(true);
当我调试它时,我看到我的_response中的totalPages是4和totalElements是3000+,所以你看到我的pagesize设置为1000所以它将返回1000个元素
这是我存储元素的IEnumerable:
IEnumerable<Stocks> stocks ;
stocks = _response.stocks.Select(p => PLSExtension.DtoToModel(p));
如何从pageNumber 2到4获取所有元素?
for(int i = _pageNumber; i <= _response.page.totalPages; i++) {
_pageNumber = _response.page.number + 1;
await SendRequest(); //My sendrequest is sending my 'await Find' again with incrimented _pageNumber
// how can I add the new return elements to 'stocks'
}
注意:即使我更改_pageSize = 1001或更高版本,它也会返回1000个元素,我认为1000是我们后端的maxPageSize
编辑:@Christian Gollhardt我相信这不是那个问题的重复,原因是,我只能通过再次发送递增的_pageNumber请求获得接下来的1000个元素,我已经尝试过了:
stocks = _response.stocks.Skip(_pageNumber * _pageSize).Take(_pageSize).Select(p => PLSExtension.DtoToModel(p));
但仍然只获得1000个元素,无法检索剩余的2000多个元素。
由于
答案 0 :(得分:0)
修正了它
private async Task SendRequest() {
_response = await _client.FindStockCombinedAsync(_pageNumber, _pageSize, "").ConfigureAwait(true);
_pageNumber = _response.page.number + 1;
}
for (int i = _pageNumber; i < _response.page.totalPages; i++) {
await SendRequest();
var stockss = _response.productLocationStocks
.Select(p => PLSExtension.DtoToModel(p));
foreach(var s in stockss) {
stocks.Add(s);
}
}