DeleteRecordsByWhereStatementAsync
Part of the IQSDataTable interface, this method deletes multiple records that match a custom SQL WHERE condition. It builds a DELETE statement from the predicate and executes or queues it.
the (BatchId) is used to associate the targeted row(s), which is useful for tracking the deleted row(s) and used later when calling SaveBatchAsync(BatchId) or SaveBatchOnlyAsync(BatchId) to apply the corresponding deletes to the data source.
The predicate parameter should be a valid SQL WHERE clause (without the WHERE keyword) that specifies the conditions for selecting records to delete.
For example: "Status = 'Cancelled' AND CreatedDate < '2023-01-01'".
The operation can be executed immediately or linked to a BatchId for batch execution. The return value indicates the number of rows deleted (immediate mode) or confirms the query was queued.
Signature
public async Task<int> DeleteRecordsByWhereStatementAsync(string predicate, Guid BatchId, bool ImmediateAction = false)Parameters
| Name | Type | Description |
|---|---|---|
predicate | string | The SQL WHERE clause (without the WHERE keyword) that determines which records to delete. Example: "Status = 'Cancelled' AND CreatedDate < '2023-01-01'". |
BatchId | Guid | A unique identifier for the batch. When ImmediateAction is false, the delete statement is added to the execution queue for this batch. |
ImmediateAction | bool (optional, default false) | If true the delete is executed immediately against the database; if false the statement is queued. |
Returns
A Task<int> representing the asynchronous operation.
- Immediate mode: the number of rows deleted (can be
0or more). - Queued mode: returns
1to indicate the query was successfully added to the batch queue.
Example Usage
// Define the data table
IQSDataTable ordersTable = QSAppContext.Tables["Orders"];
// Delete all cancelled orders older than 2023
string whereCondition = "Status = 'Cancelled' AND CreatedDate < '2023-01-01'";
Guid batchId = Guid.NewGuid();
// Queue the delete
int queuedResult = await ordersTable.DeleteRecordsByWhereStatementAsync(whereCondition, batchId);
// Execute immediately
int deletedRows = await ordersTable.DeleteRecordsByWhereStatementAsync(whereCondition, batchId, true);
Console.WriteLine($"Queued: {queuedResult}, Deleted: {deletedRows}");