All Products
Search
Document Center

Tablestore:Batch read data

Last Updated:May 12, 2026

This topic describes how to batch read data from Tablestore using the .NET SDK. You can query data from multiple tables in a single operation.

Usage notes

A single batch read operation can read up to 100 rows.

Prerequisites

Initialize the Tablestore client

Method signature

public BatchGetRowResponse BatchGetRow(BatchGetRowRequest request)

Asynchronous method:

public Task<BatchGetRowResponse> BatchGetRowAsync(BatchGetRowRequest request)

Parameters

  • rowQueryCriteriaDict (Required) IDictionary<string, MultiRowQueryCriteria>: The query criteria for the batch read operation.

    Parameter

    Type

    Description

    tableName (Required)

    string

    The name of the table.

    primaryKeys (Required)

    List<PrimaryKey>

    The primary key information, including the name and value of each primary key column.

    • Primary key column data types include STRING, INTEGER, and BINARY.

    • The number and data types of the primary keys must match those defined for the table.

    columnsToGet (Optional)

    HashSet<string>

    The columns to read. You can specify primary key columns or attribute columns.

    • Omitting this parameter returns all columns of the row data.

    • If a retrieved row does not contain any of the specified columns, the returned Row object for that row is null.

    condition (Optional)

    IColumnCondition

    The filter condition. For more information, see Filters.

    • If you specify both columnsToGet and condition, Tablestore first retrieves the columns specified in columnsToGet and then applies the filter condition.

Examples

The following code example shows how to read two rows of data whose primary key values are row1 and row2 from the test_table table.

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}");
}

The following examples show how to configure parameters for a batch read data operation.

  • To read data from multiple tables in a single batch read operation, you must specify a MultiRowQueryCriteria for each table.

    // 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);
  • Specify the attribute columns to read.

    HashSet<string> columnsToGet = new HashSet<string> { "col2" };
    
    batchGetRowRequest.Add("test_table", primaryKeys, columnsToGet);