本文介紹如何使用 .NET SDK 刪除Table Store資料表的單行資料。
前提條件
方法說明
public DeleteRowResponse DeleteRow(DeleteRowRequest request)非同步方法呼叫:
public Task<DeleteRowResponse> DeleteRowAsync(DeleteRowRequest request)範例程式碼
以下範例程式碼用於刪除 test_table 表中主索引值為 row1 的行資料。
try
{
// 構造主鍵
PrimaryKey primaryKey = new PrimaryKey
{
{ "id", new ColumnValue("row1") }
};
// 刪除行資料時必須配置刪除條件 (RowExistenceExpectation.IGNORE,表示不做行存在性判斷)
Condition condition = new Condition(RowExistenceExpectation.IGNORE);
// 調用 DeleteRow 方法刪除行資料
DeleteRowRequest deleteRowRequest = new DeleteRowRequest("test_table", condition, primaryKey);
DeleteRowResponse deleteRowResponse = client.DeleteRow(deleteRowRequest);
Console.WriteLine($"RequestId: {deleteRowResponse.RequestID}");
Console.WriteLine($"Read CU Cost: {deleteRowResponse.ConsumedCapacityUnit.Read}");
Console.WriteLine($"Write CU Cost: {deleteRowResponse.ConsumedCapacityUnit.Write}");
}
catch (Exception ex)
{
Console.WriteLine($"Delete row failed, exception: {ex.Message}");
}