Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 15881

Call method that requires 'limit' and 'offset' in Linq

$
0
0

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?


Viewing all articles
Browse latest Browse all 15881

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>