Maybe I'm asking some kind of nonsense, but I don't understand how to build LINQ query if third-party method requires parameters limit
and offset
and returns total
and items
.
What I've come to so far:
Enumerable.Range(0, maxPages /*1000*/).Select(i => i * maxLimit /*96*/).Select(offset => new { offset = offset, result = api3.SearchQuery(searchTerm, maxLimit, offset)}).TakeWhile(a => a.offset <= a.result.total).SelectMany(a => a.result.items).ToArray()
Obviously, this query makes one extra call of api3.SearchQuery
(and result will be result.items.Length == 0
, so theoretically a.offset <= a.result.total
can be replaced with a.result.items.Length > 0
).
Is there any way to get rid of extra call?