Grave uma única linha de dados em uma tabela do Tablestore com o .NET SDK.
Pré-requisitos
Método
public PutRowResponse PutRow(PutRowRequest request)
Método assíncrono:
public Task<PutRowResponse> PutRowAsync(PutRowRequest request)
Código de exemplo
O exemplo a seguir grava uma linha com valor de chave primária "row1" na tabela "test_table".
try
{
// Construct the primary key.
PrimaryKey primaryKey = new PrimaryKey
{
{ "id", new ColumnValue("row1") }
};
// Specify a condition for the write operation.
// RowExistenceExpectation.IGNORE skips the row existence check.
Condition condition = new Condition(RowExistenceExpectation.IGNORE);
// Call the PutRow method to write the row.
PutRowRequest putRowRequest = new PutRowRequest("test_table", condition, primaryKey, null);
PutRowResponse putRowResponse = client.PutRow(putRowRequest);
Console.WriteLine($"* RequestId: {putRowResponse.RequestID}");
Console.WriteLine($"* Read CU Cost: {putRowResponse.ConsumedCapacityUnit.Read}");
Console.WriteLine($"* Write CU Cost: {putRowResponse.ConsumedCapacityUnit.Write}");
}
catch (Exception ex)
{
Console.WriteLine($"Put row failed, exception: {ex.Message}");
}
-
Adicione colunas de atributo.
AttributeColumns columns = new AttributeColumns { { "col1", new ColumnValue("val1") } }; // Create a PutRowRequest. PutRowRequest putRowRequest = new PutRowRequest("test_table", condition, primaryKey, columns);