Tablestore .NET SDK'yı kullanarak tek bir satırı güncelleyin. Öznitelik sütunu değerlerini değiştirebilir, sütun ekleyebilir veya belirli sürümleri ya da tüm öznitelik sütunlarını silebilirsiniz.
Ön koşullar
Yöntem
public UpdateRowResponse UpdateRow(UpdateRowRequest request)
Zaman uyumsuz yöntem:
public Task<UpdateRowResponse> UpdateRowAsync(UpdateRowRequest request)
Örnek kod
Bu örnek, birincil anahtarı row1 olan satırı günceller ve col1 öznitelik sütununun değerini changed_val1 olarak ayarlar.
try
{
// Construct the primary key.
PrimaryKey primaryKey = new PrimaryKey
{
{ "id", new ColumnValue("row1") }
};
// Define the attribute columns to update.
UpdateOfAttribute updateOfAttribute = new UpdateOfAttribute();
updateOfAttribute.AddAttributeColumnToPut("col1", new ColumnValue("changed_val1"));
// You must specify a condition when updating a row. (RowExistenceExpectation.IGNORE skips the row existence check.)
Condition condition = new Condition(RowExistenceExpectation.IGNORE);
// Call the UpdateRow method to update the row.
UpdateRowRequest updateRowRequest = new UpdateRowRequest("test_table", condition, primaryKey, updateOfAttribute);
UpdateRowResponse updateRowResponse = client.UpdateRow(updateRowRequest);
Console.WriteLine($"RequestId: {updateRowResponse.RequestID}");
Console.WriteLine($"Read CU Cost: {updateRowResponse.ConsumedCapacityUnit.Read}");
Console.WriteLine($"Write CU Cost: {updateRowResponse.ConsumedCapacityUnit.Write}");
}
catch (Exception ex)
{
Console.WriteLine($"Update row failed, exception: {ex.Message}");
}
Aşağıdaki işlemleri de yapabilirsiniz:
-
Bir öznitelik sütunu ekleyin.
updateOfAttribute.AddAttributeColumnToPut("col2", new ColumnValue("val2")); -
Tüm bir öznitelik sütununu silin.
updateOfAttribute.AddAttributeColumnToDelete("col2");