Delete a single row from a Tablestore table by using the .NET SDK.
Prerequisites
Method
public DeleteRowResponse DeleteRow(DeleteRowRequest request)
Asynchronous method:
public Task<DeleteRowResponse> DeleteRowAsync(DeleteRowRequest request)
Sample code
The following example deletes the row whose primary key value is "row1" from the test_table table.
try
{
// Construct the primary key.
PrimaryKey primaryKey = new PrimaryKey
{
{ "id", new ColumnValue("row1") }
};
// A condition is required to delete a row. RowExistenceExpectation.IGNORE indicates that the operation proceeds without checking if the row exists.
Condition condition = new Condition(RowExistenceExpectation.IGNORE);
// Send the request to delete the row.
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}");
}