Skip to content

Mise Deletes

SteffenBlake edited this page Sep 28, 2026 · 1 revision

Deletes

DeleteFrom builds a DELETE statement. Where narrows its target rows, and DbWriter.ExecuteAsync returns the affected-row count.

Delete a course

var command = new PostgreSqlCommandBuilder()
    .DeleteFrom($"{CourseTbl.Table:raw}")
    .Where($"{CourseTbl.CourseIdCol:raw} = {courseId}");

Result<int> deleted = await writer.ExecuteAsync(command, cancellationToken);

Repeated predicates combine with AND. Ordinary interpolation holes remain parameters. The target can be set only once.

Zero affected rows is a successful count, including when the course was already absent. That can fit an idempotent delete operation. Return NotFound yourself if the application's contract requires it.

Delete a selected set

var command = new PostgreSqlCommandBuilder()
    .DeleteFrom($"{CourseTbl.Table:raw}")
    .Where($"{CourseTbl.CapacityCol:raw} = {0}")
    .Where($"{CourseTbl.CampusIdCol:raw} IS NULL");

An omitted WHERE deletes all target rows. The builder allows that operation. Foreign keys, cascade behavior, triggers, and permission checks remain database concerns and can affect execution or row counts.

Return deleted values

PostgreSQL and SQLite can return deleted rows with RETURNING. MariaDB's builder also supports DELETE RETURNING. The SQL Server builder exposes OUTPUT INSERTED for inserts and updates, which does not apply to deletes. Use trusted custom SQL when you need provider-specific delete output not exposed by the fluent builder.

A returning delete can retrieve the row and remove it in one statement. Map the output using ReturningListAsync<T> or ReturningFirstOrNotFoundAsync<T>. See Returned rows.

Rollback

Deletes participate in the writer's active transaction. A provided Partie command writer uses the command unit of work; direct writers need explicit transaction setup when rollback is required. See Transactions and Mise in ASP.NET Core.

Clone this wiki locally