【问题标题】:Rows not being Deleted from Azure CloudTable未从 Azure CloudTable 中删除的行
【发布时间】:2021-10-27 11:51:14
【问题描述】:

我正在尝试从我的 Azure CloudTable 中删除行,但这些行并未被删除。代码执行没有错误,我得到 HTTP 204 成功结果。我尝试了几种删除这些行的方法,但它们都没有真正删除这些行。

            var query = new TableQuery<SearchCompletedEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey"
                    , QueryComparisons.Equal
                    , requestId)); ;
            var result = await _table.ExecuteQuerySegmentedAsync(query, null);

            var batchDeleteOperation = new TableBatchOperation();
            foreach (var row in result)
            { batchDeleteOperation.Delete(row); }

            await _table.ExecuteBatchAsync(batchDeleteOperation);

【问题讨论】:

  • ExecuteBatchAsync 返回TableBatchResult 类型的对象。你能检查一下你得到了什么吗?
  • @GauravMantri, HttpStatusCode = 204 并且 Result 是我要删除的行。
  • 您使用的 SDK 是什么,您尝试批量删除多少项?
  • 我正在使用 Microsoft.Azure.Cosmos.Table v1.0.8。这个测试批次只有 1 个项目,但有可能有很多——尽管远不及 100 个。我也尝试过不使用批处理,得到的结果基本相同。
  • 非常感谢@GauravMantri。我改变了我的代码来初始化我的表,就像你做的那样,我的代码现在可以工作了。我正在使用 CloudStorageAccount.Parse(connString); cloudStorageAccount.CreateCloudTableClient().

标签: .net-core azure-storage azure-table-storage


【解决方案1】:

根据 Gaurav Mantri 的样本,我发现如果我更改了初始化表的方式,我能够成功删除记录。我不确定之前代码的具体问题是什么,但我想发布更改,以便对其他人有所帮助。

以前的代码不允许删除记录

var storageAccount = CloudStorageAccount.Parse(configuration.ConnectionString);
var tableClient = storageAccount.CreateCloudTableClient();

更新了允许删除记录的代码

var storageCredentials = new StorageCredentials(configuration.AccountName, configuration.AccountKey);
var tableClient = new CloudTableClient(new Uri(configuration.SearchCompletedTableUrl), storageCredentials);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-09
    • 2019-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    • 2013-08-26
    相关资源
    最近更新 更多