Azure Table:如何编写范围查询以过滤分区键

Azure Table: How to write a range query to filter on partition key

我将当前 UTC 日期向下舍入到最接近的分钟并将其转换为刻度以将结果保存为 Azure Table 存储中的 PartitionKey。我想 运行 范围查询以获取代码中的特定分区键范围。我正在使用 C#,但显然不支持以下 LINQ 操作。

var tableQuery = cloudTable.CreateQuery<Log>().Where(x => long.Parse(x.PartitionKey) <= ticks); 

投掷

System.NotSupportedException: 'The expression (Parse([10007].PartitionKey) <= 637224147600000000) is not supported.'

我也试过String.Compare(),但也没用。那么,如何在 C# 中编写过滤查询来获取小于或等于给定刻度的记录?请注意,分区键是这样选择的,以便记录可以自然地按时间降序排序。

下面是我用来取数据的例子。根据您的情况尝试以下查询。我觉得应该可以。

public async Task<Advertisement> GetAdvertisementBy(string id, string user)
    {
        List<Advertisement> list = new List<Advertisement>();
        // Initialize the continuation token to null to start from the beginning of the table.
        TableContinuationToken continuationToken = null;
        var filter1 = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, user);
        var filter3 = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, id);
        var combine = TableQuery.CombineFilters(filter1, TableOperators.And, filter3);
        TableQuery<Advertisement> query = new TableQuery<Advertisement>().Where(combine);
        do
        {
            // Retrieve a segment (up to 1,000 entities).
            TableQuerySegment<Advertisement> tableQueryResult = await base.Table.ExecuteQuerySegmentedAsync(query, continuationToken);
            // Assign the new continuation token to tell the service where to
            // continue on the next iteration (or null if it has reached the end).
            continuationToken = tableQueryResult.ContinuationToken;
            list.AddRange(tableQueryResult.Results);
            // Loop until a null continuation token is received, indicating the end of the table.
        } while (continuationToken != null);

        return list.FirstOrDefault();
    }