4

For my Quickbooks Online integration, I'm using the .NET SDK and was previously using LINQ to access data from a ServiceContext:

var paymentMethodsService = new QueryService<PaymentMethod>(ServiceContext);
_paymentMethods = paymentMethodsService.Select(x => x).ToList();

When testing, we noticed that this only returns the first 100 records. (Presumably because this is the default page size?)

We can get around this by using a query containing MAXRESULTS:

var itemsService = new QueryService<Item>(ServiceContext);
_items = itemsService.ExecuteIdsQuery("SELECT * FROM Item MAXRESULTS 1000").ToList();

My question is, can I achieve the same result without using a query string?

Tom Wright
  • 11,278
  • 15
  • 74
  • 148
  • Do you have more than 100 records in the database? Did you try the string query to see if you got back more data? – jdweng Jun 02 '17 at 17:16
  • @jdweng Yes the query string returns 300+ records, so it's not the end of the world if there's no other way. Would just prefer to avoid a hard coded query string if possible. – Tom Wright Jun 02 '17 at 17:17
  • And what if you do `Take(10000).Select(...)`? – Evk Jun 02 '17 at 17:27
  • @Evk D'oh! This is what I get for posting to Stack on a Friday afternoon. Of course that works. If you want to put that into an answer, I'll gladly accept it. – Tom Wright Jun 05 '17 at 09:49

1 Answers1

0

I must admit I have no idea what Quickbooks Online even is, but nevertheless I think you can override default page size with LINQ Take(yourPageSize). Though it's still not clear how to fetch ALL items in a collection this way, without knowing total count beforehand. Hopefully you don't need to do this in your scenario (or if you do - maybe you can just use arbitrary large number for Take if you won't find another way).

Evk
  • 98,527
  • 8
  • 141
  • 191
  • The bit you don't (couldn't) know is that 1,000 is the maximum allowed page size. In my case I'm not expecting the list to ever have more than this number of entries, but I'll be adding a check that calls `.Skip(1000)` when 1,000 elements are returned to my first call. – Tom Wright Jun 05 '17 at 11:00