【问题标题】:Azure table Storage - Table service Query to retrieve and return 10 entities till last entityAzure 表存储 - 表服务查询以检索并返回 10 个实体,直到最后一个实体
【发布时间】:2021-08-17 19:21:16
【问题描述】:

我有一个包含 2000 多个实体的表存储表。执行表服务查询以一次性获取所有 2000 个实体需要时间。所以我试图使用 LINQ Take 运算符,但它只返回 10 个实体。在所有 2000 个实体之前,应该如何获取并返回接下来的 10 个实体?

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

【问题讨论】:

  • 你试过分页吗?
  • skip 重新打开问题不是 Azure 存储表支持的 LINQ 运算符。
  • 请编辑您的问题并提供完整的代码。谢谢。

标签: azure entity-framework linq azure-table-storage azure-tablequery


【解决方案1】:

我认为你应该使用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);  

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

【讨论】:

  • 谢谢@Vova Bilyachat。您能否提供一个示例,如何使用令牌从客户端 jquery ajax 进行调用以及如何在 C# 中处理它
猜你喜欢
  • 2017-11-06
  • 1970-01-01
  • 1970-01-01
  • 2013-04-02
  • 2018-12-08
  • 1970-01-01
  • 1970-01-01
  • 2017-06-30
  • 1970-01-01
相关资源
最近更新 更多