Can I use LINQ to skip a collection and just return 100 records?

.net, azure, c#, linq

Solution

As you already stated in your question, the Skip method is not implemented in Windows Azure Table storage. This means you have 2 options left:

Option 1

Download all data from table storage (by using ToList, see abatishchev's answer) and execute the Skip and Take methods on this complete list. In your question you're talking about 500 records. If the number of records doesn't grow too much this solution should be OK for you, just make sure that all records have the same partition key.

If the data grows you can still use this approach, but I suggest you evaluate a caching solution to store all the records instead of loading them from table storage over and over again (this will improve the performance, but don't expect this to work with very large amounts of data). Caching is possible in Windows Azure using:

- Windows Azure Caching (Preview)

- Windows Azure Shared Caching

Option 2

The CloudTableQuery class allows you to query for data, but more important to receive a continuation token to build a paging implementation. This allows you to detect if you can query for more data, the pagination example on Scott's blogpost (see nemensv's comment) uses this.

For more information on continuation tokens I suggest you take a look at Jim's blogpost: Azure@home Part 7: Asynchronous Table Storage Pagination. By using continuation tokens you only download the data for the current page meaning it will also work correctly even if you have millions of records. But you have to know the downside of using continuation tokens:

- This won't work with the Skip method out of the box, so it might not be a solution for you.

- No page 'numbers', because you only know if there's more data (not how much)

- No way to count all records

Problem

I have the following that returns a collection from Azure table storage where `Skip` is not implemented. The number of rows returned is approximately 500. ``` ICollection<City> a = cityService.Get("0001I"); ``` What I would like to do is to be able to depending on an argument have just the following ranges returned: ``` records 1-100 passing in 0 as an argument to a LINQ expression records 101-200 passing in 100 as an argument to a LINQ expression records 201-300 passing in 200 as an argument to a LINQ expression records 301-400 passing in 300 as an argument to a LINQ expression etc ``` Is there some way I can add to the above and use link to get these ranges of records returned:

Original source