我将当前UTC日期四舍五入到最近的分钟,并将其转换为刻度,以将结果另存为PartitionKey
在Azure Table存储中。我想运行范围查询以获取代码中的特定分区键范围。我正在使用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();
}