This topic describes how to read a single row of data from a Tablestore data table by using the .NET SDK.
Usage notes
When you read data, you must provide the complete primary key value, including the value of any auto-increment primary key column.
Prerequisites
Method
public GetRowResponse GetRow(GetRowRequest request)Asynchronous method:
public Task<GetRowResponse> GetRowAsync(GetRowRequest request)Code example
This example reads a single row with the primary key value 'row1'.
try
{
// Construct the primary key.
PrimaryKey primaryKey = new PrimaryKey
{
{ "id", new ColumnValue("row1") }
};
// Call the GetRow method to read the row.
GetRowRequest getRowRequest = new GetRowRequest("test_table", primaryKey);
GetRowResponse getRowResponse = client.GetRow(getRowRequest);
Console.WriteLine($"RequestId: {getRowResponse.RequestID}");
Console.WriteLine($"Read CU Cost: {getRowResponse.ConsumedCapacityUnit.Read}");
Console.WriteLine($"Write CU Cost: {getRowResponse.ConsumedCapacityUnit.Write}");
Console.WriteLine($"Row Data: {getRowResponse.Row}");
}
catch (Exception ex)
{
Console.WriteLine($"Get row failed, exception: {ex.Message}");
}Specify a version range for the data to read. The method returns only data within the specified version range.
TimeRange timeRange = new TimeRange { StartTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - 86400 * 1000, EndTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }; // Call the GetRow method to read the row. GetRowRequest getRowRequest = new GetRowRequest("test_table", primaryKey, null, null, timeRange);Specify the attribute columns to read.
HashSet<string> columnsToGet = new HashSet<string> { "col2" }; // Call the GetRow method to read the row. GetRowRequest getRowRequest = new GetRowRequest("test_table", primaryKey, columnsToGet);