我正在将我所有的azure表存储功能升级到Azure.Data.Tables库,因为Microsoft.Azure.Cosmos.Table SDK已被弃用.
我使用Cosmos包中的代码轻松地加载了批量数据.
try {
var pks = entities.Select(x => x.PartitionKey).Distinct().ToList();
foreach (var pk in pks) {
await AddSymbolIfNotExistOrUpdateLastRecordDateAsync(pk, entities[0].RowKey);
var records = entities.Where(x => x.PartitionKey == pk).Distinct().ToList(); // partition key is the symbol
var batches = records.Batch(100); //batching max value is 100
completionMessage.Append($" A storage batch started for {records.Count} {pk} records into the table: {tableName} ");
#region BATCH JOB
//Iterating through each batch
foreach (var block in batches) {
var batchOperationObj = new TableBatchOperation();
foreach (var record in block) {
batchOperationObj.InsertOrReplace(record);
}
try {
var worked = await table?.ExecuteBatchAsync(batchOperationObj)! != null;
if (worked) {
batchResponse.NumberOfRecordsProcessed += batchOperationObj.Count;
batchOperationObj.Clear();
}
} // rest removed for brevity
我找不到任何方法、示例或教程来说明如何使用此SDK插入批次.有没有可能用它行不通呢?只有用于单一实体的Add方法.
任何 idea 都值得欣赏,因为我一次加载数千条记录,只是无法想象通过迭代来做是唯一的方法.