【问题标题】:Azure Table Query Delete Items Not In List for Specified ColumnAzure表查询删除指定列的列表中没有的项目
【发布时间】:2018-05-23 21:53:01
【问题描述】:

如果我有一个看起来像这样的Azure Table

PartitionKey | RowKey | Timestamp | InstanceId

我有 InstanceIds ab。我想删除表中未列出的InstanceIds 中的所有项目(如c)。 InstanceIds 跨越 Partition 边界。我知道怎么做BatchDelete。但我不确定如何查询不是ab 的项目。

【问题讨论】:

    标签: c# azure azure-table-storage


    【解决方案1】:

    如果你的InstanceId 类型是字符串,

    var query = new TableQuery<EntityType>()
        .Where(
             TableQuery.CombineFilters(
                 TableQuery.GenerateFilterCondition("InstanceId", QueryComparisons.NotEqual, "a"), 
                 TableOperators.And,
                 TableQuery.GenerateFilterCondition("InstanceId", QueryComparisons.NotEqual, "b")
        ));
    
    //Or you can build the filter string directly
    var query = new TableQuery<EntityType>().Where("(InstanceId ne 'a') and (InstanceId ne 'b')");
    

    如果是int,类似操作。

    var query = new TableQuery<EntityType>()
        .Where(
            TableQuery.CombineFilters(
                TableQuery.GenerateFilterConditionForInt("InstanceId", QueryComparisons.NotEqual, a), 
                TableOperators.And, 
                TableQuery.GenerateFilterConditionForInt("InstanceId", QueryComparisons.NotEqual, b)
        ));
    
    //Or build the filter string directly
    var query = new TableQuery<EntityType>().Where("(InstanceId ne a) and (InstanceId ne b)");
    

    然后使用ExecuteQuery获取你需要的查询结果。一个例子:

    var entriesResult = table.ExecuteQuerySegmentedAsync(query, continuationToken).Result.Results;
    

    【讨论】:

      猜你喜欢
      • 2017-09-03
      • 1970-01-01
      • 2016-01-29
      • 2021-04-09
      • 1970-01-01
      • 2022-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多