azureentity-frameworklinqazure-table-storageazure-tablequery

Azure table Storage - Table service Query to retrieve and return 10 entities till last entity


I have a table storage table which has more than 2000 entities. Performing Table service query execution to fetch all 2000 entities in one go is taking time. So I was trying to use LINQ Take operator but it is returning only 10 entities. What should be done to fetch and return the next 10 entities till all 2000 entities?

      var query = (from entity in context.CreateQuery<Customer>("FirstTenEntities")  
             select entity).Take(10);  

Solution

  • I think you should use segmented tokens

    string filter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Sales");
    TableQuery<EmployeeEntity> employeeQuery = new TableQuery<EmployeeEntity>().Where(filter);
    employeeQuery.TakeCount = 50;  
    
    TableContinuationToken continuationToken = null;
    do
    {
        var employees = employeeTable.ExecuteQuerySegmented(employeeQuery, continuationToken);
        foreach (var emp in employees)
        {
            // ...
        }
        
        continuationToken = employees.ContinuationToken;
    } while (continuationToken != null);  
    

    That way if you are returning data to the client you will need to return this token back so you can fetch next batch