Is it possible to use LINQ to skip a collection and just return 100 records?

I have the following that returns a collection from Azure table storage where Skip not implemented. The number of rows returned is about 500.

 ICollection<City> a = cityService.Get("0001I"); 

What I would like to do is to be able, depending on the argument, to have only the following ranges:

 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 a way to add to the above and use the link to get these ranges of returned records:

+4
source share
4 answers

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

Option 1

Download all the data from the table storage (using ToList, see abatishchev answer) and execute the Skip and Take methods in this full list. In your question you are talking about 500 entries. If the number of records is not too large, this solution should be ok for you, just make sure that all records have the same partition key.

If the data is growing, you can still use this approach, but I suggest that you evaluate the caching solution to keep all records and not load them from the table storage again and again (this will improve performance, but does not expect this to work with very large volumes data). Caching is possible on Windows Azure using:

Option 2

The CloudTableQuery class allows you to query data, but it’s more important to get a continuation token to create a paging implementation. This allows you to determine if you can request additional data; an example of a page on Scott's blog (see nemensv's comment) uses this.

For more information on continuing tokens, I suggest you take a look at Jim's blog blog: Azure @home Part 7: Asynchronous Paging . Using continuation tokens, you only load data for the current page, which means that it will also work correctly, even if you have millions of records. But you should know the disadvantages of using continuation tokens:

  • This will not work with the Skip method out of the box, so this may not be the solution for you.
  • There are no page numbers because you only know if there is more data (and not how much)
  • Unable to read all records
+3
source

If swapping is not supported by the base engine, the only way to implement it is to load all the data into memory and then swap:

 var list = cityService.Get("0001I").ToList(); // meterialize var result = list.Skip(x).Take(y); 
0
source

Try something like this:

 cityService.Get("0001I").ToList().Skip(n).Take(100); 

This should return 201-300 entries:

 cityService.Get("0001I").ToList().Skip(200).Take(100); 
-1
source
 a.AsEnumerable().Skip(m).Take(n) 
-1
source

All Articles