Azure表存储-表服务查询以检索并返回10个实体,直到最后一个实体



我有一个表存储表,它有2000多个实体。执行表服务查询以一次性获取所有2000个实体需要时间。所以我尝试使用LINQ Take操作符,但它只返回了10个实体。应该做些什么来获取和返回接下来的10个实体,直到所有2000个实体?

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

我认为您应该使用分段令牌

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);  

这样,如果您将数据返回到客户端,则需要返回此令牌,以便获取下一批

最新更新