Tüm Ürünler
Search
Belge Merkezi

Tablestore:Batch read data

Son Güncelleme:Oct 02, 2026

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

Tablestore istemcisini başlatma

Yöntem imzası

public BatchGetRowResponse BatchGetRow(BatchGetRowRequest request)

Eşzamansız yöntem:

public Task<BatchGetRowResponse> BatchGetRowAsync(BatchGetRowRequest request)

Parametreler

  • rowQueryCriteriaDict (Gerekli) IDictionary<string, MultiRowQueryCriteria>: Toplu okuma işlemi için sorgu kriterleri.

    Parametre

    Tür

    Açıklama

    tableName (Gerekli)

    string

    Tablo adı.

    primaryKeys (Gerekli)

    List<PrimaryKey>

    Her bir birincil anahtar sütununun adını ve değerini içeren birincil anahtar bilgileri.

    • Birincil anahtar sütunu veri türleri STRING, INTEGER ve BINARY'dir.

    • Birincil anahtarların sayısı ve veri türleri, tablo için tanımlananlarla eşleşmelidir.

    columnsToGet (İsteğe bağlı)

    HashSet<string>

    Okunacak sütunlar. Birincil anahtar sütunlarını veya nitelik sütunlarını belirtebilirsiniz.

    • Bu parametreyi belirtmezseniz satır verilerinin tüm sütunları döner.

    • Alınan bir satır belirtilen sütunlardan hiçbirini içermiyorsa bu satır için döndürülen Row nesnesi null olur.

    condition (İsteğe bağlı)

    IColumnCondition

    Filtre koşulu. Daha fazla bilgi için bkz. Filtreler.

    • columnsToGet ve condition parametrelerinin ikisini de belirtirseniz Tablestore önce columnsToGet içinde belirtilen sütunları alır ardından filtre koşulunu uygular.

Ö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);