Class DeleteBuilder<TEntity>
Fluent builder for a DELETE statement, started with
CreateDeleteBuilder<TEntity>(IDataContext, Action<EntityMetadataBuilder<TEntity>>?). The rows to remove are selected either by a
predicate (Where(Expression<Func<TEntity, bool>>)) or explicitly as the whole table (All()); both render a
parameterised DELETE FROM <table> [WHERE ...]. There is deliberately no change tracking:
the terminal issues exactly one explicit command.
public sealed class DeleteBuilder<TEntity>
Type Parameters
TEntityThe mapped entity type whose rows are deleted.
- Inheritance
-
DeleteBuilder<TEntity>
- Inherited Members
- Extension Methods
Methods
All()
Deletes every row of the table. Required (and only meaningful) when no Where(Expression<Func<TEntity, bool>>) is given, so an accidental full-table delete cannot be written by omitting the predicate.
public DeleteBuilder<TEntity> All()
Returns
- DeleteBuilder<TEntity>
This builder, for chaining.
Exceptions
- InvalidOperationException
Where(Expression<Func<TEntity, bool>>) was already called.
Delete()
Executes the delete and returns the number of affected rows.
public int Delete()
Returns
- int
The number of deleted rows, as reported by the provider.
Exceptions
- InvalidOperationException
Neither Where(Expression<Func<TEntity, bool>>) nor All() was called.
- NotSupportedException
The context is not database-backed (for example the in-memory provider).
DeleteAsync(CancellationToken)
Asynchronously executes the delete and returns the number of affected rows.
public Task<int> DeleteAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancels execution.
Returns
Exceptions
- InvalidOperationException
Neither Where(Expression<Func<TEntity, bool>>) nor All() was called.
- NotSupportedException
The context is not database-backed (for example the in-memory provider).
IgnoreFilters()
Disables all global query filters declared for the target entity type, so the delete (in the predicate form and the key form) removes the unfiltered rows. All() stays an explicit full-table delete and is never filtered. Repeatable: a later call accumulates with the earlier scope.
public DeleteBuilder<TEntity> IgnoreFilters()
Returns
- DeleteBuilder<TEntity>
This builder, for chaining.
IgnoreFilters(IEnumerable<string>)
Disables the named global query filters identified by filterKeys on the target
entity type. An empty or null filterKeys disables nothing.
Repeatable: a later call accumulates (union) with the earlier scope.
public DeleteBuilder<TEntity> IgnoreFilters(IEnumerable<string> filterKeys)
Parameters
filterKeysIEnumerable<string>The filter keys to disable.
Returns
- DeleteBuilder<TEntity>
This builder, for chaining.
IgnoreFilters(IEnumerable<string>, params Type[])
Disables the named global query filters identified by filterKeys only on the
given entityTypes (the intersection of keys and types); an empty
entityTypes means any entity type. The key list is the gate: an empty or
null filterKeys disables nothing even when entity types are
supplied. Repeatable: a later call accumulates (union) with the earlier scope.
public DeleteBuilder<TEntity> IgnoreFilters(IEnumerable<string> filterKeys, params Type[] entityTypes)
Parameters
filterKeysIEnumerable<string>The filter keys to disable.
entityTypesType[]The entity types the disable is scoped to; empty means any entity type.
Returns
- DeleteBuilder<TEntity>
This builder, for chaining.
IgnoreFilters(params Type[])
Disables every global query filter declared for the given entity types. An empty or
null entityTypes disables nothing. Repeatable: a later call
accumulates (union) with the earlier scope.
public DeleteBuilder<TEntity> IgnoreFilters(params Type[] entityTypes)
Parameters
entityTypesType[]The entity types whose filters are disabled.
Returns
- DeleteBuilder<TEntity>
This builder, for chaining.
Returning()
Switches the builder to a row-returning terminal that materialises the whole deleted row through
the provider's RETURNING/OUTPUT form.
public DeleteReturningBuilder<TEntity, TEntity> Returning()
Returns
- DeleteReturningBuilder<TEntity, TEntity>
A returning builder whose terminals produce
TEntity.
Returning<TResult>(Expression<Func<TEntity, TResult>>)
Switches the builder to a row-returning terminal that materialises a projection of the deleted
row through the provider's RETURNING/OUTPUT form. The projection may be the
identity, a single mapped property, an anonymous type, a positional constructor or a
member-init; it may only reference mapped properties.
public DeleteReturningBuilder<TEntity, TResult> Returning<TResult>(Expression<Func<TEntity, TResult>> projection)
Parameters
projectionExpression<Func<TEntity, TResult>>Selects the mapped columns to return.
Returns
- DeleteReturningBuilder<TEntity, TResult>
A returning builder whose terminals produce
TResult.
Type Parameters
TResultThe projected row shape.
Exceptions
- NotSupportedException
The projection references something other than mapped properties.
ToSql()
Renders the parameterised SQL this builder would execute, without executing it. Useful for diagnostics and for verifying SQL generation without a database.
public string ToSql()
Returns
- string
The rendered SQL text.
Exceptions
- InvalidOperationException
Neither Where(Expression<Func<TEntity, bool>>) nor All() was called.
- NotSupportedException
The context is not database-backed (for example the in-memory provider).
Where(Expression<Func<TEntity, bool>>)
Restricts the delete to the rows satisfying predicate. The predicate is
translated by the same expression pipeline as a SELECT WHERE; captured variables
become parameters, inline literals are emitted verbatim. Repeating the call combines the
predicates with and (matching From<T>().Where(...)).
public DeleteBuilder<TEntity> Where(Expression<Func<TEntity, bool>> predicate)
Parameters
predicateExpression<Func<TEntity, bool>>The condition each deleted row must satisfy.
Returns
- DeleteBuilder<TEntity>
This builder, for chaining.
Exceptions
- InvalidOperationException
All() was already called.