Este tópico descreve como ler uma única linha de dados de uma tabela do Tablestore com o .NET SDK.
Observações de uso
Na leitura de dados, forneça o valor completo da chave primária, inclusive o valor de qualquer coluna de chave primária com incremento automático.
Pré-requisitos
Método
public GetRowResponse GetRow(GetRowRequest request)
Método assíncrono:
public Task<GetRowResponse> GetRowAsync(GetRowRequest request)
Exemplo de código
Este exemplo lê uma única linha com o valor de chave primária '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}");
}
-
Especifique um intervalo de versões para os dados a ler. O método retorna apenas os dados dentro do intervalo especificado.
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); -
Defina as colunas de atributo a ler.
HashSet<string> columnsToGet = new HashSet<string> { "col2" }; // Call the GetRow method to read the row. GetRowRequest getRowRequest = new GetRowRequest("test_table", primaryKey, columnsToGet);