Bu konuda, .NET SDK kullanarak Tablestore'dan toplu veri okuma işlemi açıklanmaktadır. Tek bir işlemde birden çok tablodan veri sorgulayabilirsiniz.
Kullanım notları
Tek bir toplu okuma işleminde en fazla 100 satır okuyabilirsiniz.
Ön koşullar
Yöntem imzası
public BatchGetRowResponse BatchGetRow(BatchGetRowRequest request)
Eşzamansız yöntem:
public Task<BatchGetRowResponse> BatchGetRowAsync(BatchGetRowRequest request)
Örnekler
Aşağıdaki kod örneği test_table tablosundan birincil anahtar değerleri row1 ve row2 olan iki satır verinin nasıl okunacağını gösterir.
try
{
List<PrimaryKey> primaryKeys = new List<PrimaryKey>
{
// Add the primary key of the first row.
new PrimaryKey {{ "id", new ColumnValue("row1") }},
// Add the primary key of the second row.
new PrimaryKey {{ "id", new ColumnValue("row2") }},
};
// Construct the query criteria.
BatchGetRowRequest batchGetRowRequest = new BatchGetRowRequest();
batchGetRowRequest.Add("test_table", primaryKeys);
// Call the BatchGetRow method to read row data.
BatchGetRowResponse batchGetRowResponse = client.BatchGetRow(batchGetRowRequest);
// Process the response.
Console.WriteLine($"* RequestId: {batchGetRowResponse.RequestID}");
Console.WriteLine($"* Is all succeeded: {batchGetRowResponse.IsAllSucceed}");
foreach (var tableGroup in batchGetRowResponse.RowDataGroupByTable)
{
Console.WriteLine($"* Table: {tableGroup.Key}");
foreach (var item in tableGroup.Value)
{
if (item.IsOK)
{
if (item.Row != null)
{
Console.WriteLine($"Succeeded Row: {item.Row}");
}
else
{
Console.WriteLine("Succeeded Row: This row does not exist.");
}
}
else
{
Console.WriteLine($"Failed Row: {item.ErrorMessage}");
}
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Batch get row failed, exception: {ex.Message}");
}
Aşağıdaki örneklerde toplu veri okuma işlemi için parametrelerin nasıl yapılandırılacağı gösterilmektedir.
-
Tek bir toplu okuma işleminde birden çok tablodan veri okumak için her tablo için bir MultiRowQueryCriteria belirtmeniz gerekir.
// Construct the query criteria for the second table. List<PrimaryKey> primaryKeys1 = new List<PrimaryKey> { new PrimaryKey {{ "order_id", new ColumnValue("90fb478c-1360-11f0-a34d-00163e30a2a9") }} }; batchGetRowRequest.Add("orders_small", primaryKeys1); -
Okunacak nitelik sütunlarını belirtin.
HashSet<string> columnsToGet = new HashSet<string> { "col2" }; batchGetRowRequest.Add("test_table", primaryKeys, columnsToGet);