DeleteRecordByIdAsync

Part of the IQSDataTable interface, this method deletes a single record from the data source using its unique Id. The delete operation can either be executed immediately or added to a batch queue.

the (BatchId) is used to associate the targeted row, which is useful for tracking the deleted row and used later when calling SaveBatchAsync(BatchId) or SaveBatchOnlyAsync(BatchId) to apply the corresponding deletes to the data source.

When queued, the generated SQL is linked to a BatchId so that multiple operations can be committed together later. The return value indicates how many rows were affected (immediate mode) or a confirmation that the query was queued successfully.

Signature

public async Task<int> DeleteRecordByIdAsync(string RecordId, Guid BatchId, bool ImmediateAction = false)

Parameters

NameTypeDescription
RecordIdstringThe unique identifier of the record to delete.
BatchIdGuid A unique identifier for the batch. When ImmediateAction is false, the delete statement is added to the execution queue for this batch.
ImmediateActionbool (optional, default false) If true the delete is executed against the database immediately; if false (the default) the statement is queued.

Returns

A Task<int> representing the asynchronous operation.

  • Immediate mode: the number of rows deleted (typically 1 if the record existed, 0 if not).
  • Queued mode: returns 1 to indicate the query was successfully added to the batch execution queue.

Example Usage

// Define the data table
IQSDataTable customersTable = QSAppContext.Tables["Customers"];

string recordId = "00000000-0000-0000-0000-000000000001";
Guid batchId = Guid.NewGuid();

// Queue the delete (default behavior)
int queuedResult = await customersTable.DeleteRecordByIdAsync(recordId, batchId);

// Delete immediately
int deletedRows = await customersTable.DeleteRecordByIdAsync(recordId, batchId, true);

Console.WriteLine($"Queued: {queuedResult}, Deleted: {deletedRows}");