.net 删除Azure表行

.net 删除Azure表行,.net,azure,logging,azure-cosmosdb,.net,Azure,Logging,Azure Cosmosdb,我正在尝试删除旧的azure日志,这是我的代码 TableOperation tableOperation; CloudTableClient cloudTableClient = CosmosStorageAccount.CreateCloudTableClient(); foreach (var tableName in tableNames) { var table = cloudTableClient.GetTab

我正在尝试删除旧的azure日志,这是我的代码

TableOperation tableOperation;
        CloudTableClient cloudTableClient = CosmosStorageAccount.CreateCloudTableClient();

        foreach (var tableName in tableNames)
        {
            var table = cloudTableClient.GetTableReference(tableName);
            TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.LessThan, DateTimeOffset.Now.AddDays(-15).Date));
            try
            {
                var missing = 0;
                var oldRows = table.ExecuteQuery(query).ToList();
                var index = 0;
                while (index < oldRows.Count())
                {
                    if (oldRows[index] != null)
                    {
                        tableOperation = TableOperation.Delete(oldRows[index]);
                        await table.ExecuteAsync(tableOperation);
                        Debug.WriteLine(index);
                        index++;
                    }
                    else
                    {
                        missing++;
                        index++;
                    }
                }
                Debug.WriteLine($"{tableName} => Deleted : {index} , Missing : {missing}");
            }
            catch (Exception e)
            {
                var exception = e.Message;
            }
        }
    }
TableOperation TableOperation;
CloudTableClient CloudTableClient=CosmosStorageAccount.CreateCloudTableClient();
foreach(tableNames中的var tableName)
{
var table=cloudTableClient.GetTableReference(tableName);
TableQuery query=new TableQuery().Where(TableQuery.GenerateFilterConditionForDate(“Timestamp”,QueryComparisons.LessThan,DateTimeOffset.Now.AddDays(-15.Date));
尝试
{
var缺失=0;
var oldRows=table.ExecuteQuery.ToList();
var指数=0;
while(索引Deleted:{index},Missing:{Missing}”);
}
捕获(例外e)
{
var异常=e.消息;
}
}
}
问题是我一行一行地删除日志,这需要很多时间。我可以应用批处理操作逐组删除,但在我的日志表中,所有行都有不同的分区键(我认为这是一个设计错误)。是否有其他方法可以删除多行,而不是逐个删除,即使所有日志具有不同的分区键?

允许多个删除操作,但有一些注意事项要求您在执行之前将作业拆分为批,包括拆分分区键:

  • 每个请求最多100个实体
  • 每个实体只能出现一次
  • 所有实体必须具有相同的分区键
  • 总有效负载不能大于4个MiB
  • 列表项
在这些限制范围内,您可以(如果需要)在同一批中删除、更新或插入

var oldRows = table.ExecuteQuery(query).ToList();

//Divide rows into batches by partition key and max size

foreach(var batch in batches) {
  
    // Create the batch operation. 
    TableBatchOperation batchOperation = new TableBatchOperation();
    
    foreach(var doc in batch)
    {
        batchOperation.Delete(doc);
    }

    // Execute the batch operation.
    IList<TableResult> results = await table.ExecuteBatchAsync(batchOperation);
    
    //deal with the results
}
var oldRows=table.ExecuteQuery.ToList();
//按分区键和最大大小将行分成批
foreach(批量var){
//创建批处理操作。
TableBatchOperation batchOperation=新建TableBatchOperation();
foreach(批量var单据)
{
批量操作。删除(单据);
}
//执行批处理操作。
IList results=wait table.ExecuteBatchAsync(批处理操作);
//处理结果
}