Method DeleteAsync
DeleteAsync(string, MapValue, DeleteOptions, CancellationToken)
Declaration
public Task<DeleteResult<RecordValue>> DeleteAsync(string tableName, MapValue primaryKey, DeleteOptions options = null, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | tableName | Name of the table. |
| MapValue | primaryKey | Primary key of the row as MapValue representing names and values of the primary key fields. |
| DeleteOptions | options | (Optional) Options for the Delete operation.
If not specified or null, appropriate defaults will be
used. See DeleteOptions. |
| CancellationToken | cancellationToken | (Optional) Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<DeleteResult<RecordValue>> | Task returning DeleteResult<TRow>. |
Remarks
The row is identified using a primary key value.
By default, a delete operation is unconditional and will succeed if the specified row exists. Delete operations can be made conditional based on whether the RowVersion of an existing row matches that supplied by MatchVersion. Instead of using MatchVersion you may also use DeleteIfVersionAsync(string, MapValue, RowVersion, DeleteOptions, CancellationToken) API to perform the same conditional operation.
It is also possible to return information about the existing row.
The row, including its RowVersion, creation time,
and modification time can be optionally returned as part of
DeleteResult<TRow> via the
ExistingRow,
ExistingVersion,
ExistingCreationTime,
and ExistingModificationTime
properties. The
existing row information will only be returned if
ReturnExisting is true and one
of the following occurs:
- MatchVersion is specified and the operation fails because the row exists and its RowVersion does not match the specified version.
- MatchVersion is not specified and the delete operation succeeds, in which case the row, its version, creation time and modification time will be returned as they were before the deletion. Note that this information might not be available with older servers. Also note that if MatchVersion is specified and the operation succeeds, the existing row information will not be returned.
Use of ReturnExisting may result in additional consumed read capacity and may affect the operation's latency.
Note that the failures of conditional Delete operation as discussed above will not result in an exception and the DeleteResult<TRow> will still be returned.
Examples
Executing Delete operation on table with schema MyTable(id LONG, name STRING, PRIMARY KEY(id)).var result = await client.DeleteAsync(
"MyTable",
new MapValue
{
["id"] = 1000
});
// true if the delete succeeded, false if the row was not found
Console.WriteLine(result.Success);
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If
tableName is null or invalid or
primaryKey is null or invalid or
options contains invalid values. |
| TimeoutException | Operation has timed out. |
| InvalidOperationException | The table or the service is not in a valid state to perform this operation. |
| NoSQLException | NoSQLException or one of its subclasses is thrown if operation cannot be performed for any other reason. See documentation for corresponding subclass of NoSQLException. |