Class UpdateReturningBuilder<TEntity, TResult>
Fluent terminal for an UPDATE that returns the updated rows through the provider's
RETURNING/OUTPUT form, started with
Returning() or
Returning<TResult>(Expression<Func<TEntity, TResult>>).
The returned rows are materialised with the same projection pipeline as a query; every terminal reads
the result through Single() or ToList().
public sealed class UpdateReturningBuilder<TEntity, TResult>
Type Parameters
TEntityThe mapped entity type whose rows are updated.
TResultThe materialized row type (the entity or a projection).
- Inheritance
-
UpdateReturningBuilder<TEntity, TResult>
- Inherited Members
- Extension Methods
Methods
OutputInto(string)
Writes the updated rows into targetTable through SQL Server's
OUTPUT ... INTO clause instead of returning them to the client. The target must already
exist with columns whose names match the selected output columns.
public OutputIntoBuilder OutputInto(string targetTable)
Parameters
targetTablestringThe raw (unquoted) target table name.
Returns
- OutputIntoBuilder
An output-into terminal whose
Executewrites the rows and returns the affected-row count.
Exceptions
- ArgumentException
targetTableis null or empty.
OutputIntoTableVariable(string, string)
Writes the updated rows into a table variable through SQL Server's OUTPUT ... INTO clause
instead of returning them to the client. The batch declares the variable from
columnDefinitions, writes the selected output columns into it and reads them back:
DECLARE @t TABLE (<definitions>); UPDATE ... OUTPUT ... INTO @t (...); SELECT ... FROM @t;.
Providers without OUTPUT INTO reject the statement with NotSupportedException
when it renders.
public OutputIntoBuilder OutputIntoTableVariable(string variableName, string columnDefinitions)
Parameters
variableNamestringThe table-variable name, including the leading
@; never bracketed or quoted.columnDefinitionsstringThe trusted column-definition text of the
DECLARE @t TABLE (...)declaration; embedded verbatim and never parameterised.
Returns
- OutputIntoBuilder
An output-into terminal whose
Executewrites the rows and returns the affected-row count.
Exceptions
- ArgumentException
variableNameis not a bare table-variable name, orcolumnDefinitionsis null or empty.
OutputIntoThenOutput(string)
Writes the updated rows into targetTable and also returns them to the client
through a second OUTPUT clause (SQL Server). Chain a row terminal such as
ToList() on the returned builder.
public UpdateReturningBuilder<TEntity, TResult> OutputIntoThenOutput(string targetTable)
Parameters
targetTablestringThe raw (unquoted) target table name.
Returns
- UpdateReturningBuilder<TEntity, TResult>
A returning builder that writes into the target and returns the same rows to the client.
Exceptions
- ArgumentException
targetTableis null or empty.
Single()
Executes the update and returns the single updated row.
public TResult Single()
Returns
- TResult
The materialized row.
Exceptions
- InvalidOperationException
The update touched no row, or more than one; use ToList().
- NotSupportedException
The provider cannot return updated rows, or the context is read-only.
SingleAsync(CancellationToken)
Asynchronously executes the update and returns the single updated row.
public Task<TResult> SingleAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancels execution.
Returns
- Task<TResult>
A task producing the materialized row.
Exceptions
- InvalidOperationException
The update touched no row, or more than one; use ToListAsync(CancellationToken).
- NotSupportedException
The provider cannot return updated rows, or the context is read-only.
ToList()
Executes the update and returns every updated row.
public IReadOnlyList<TResult> ToList()
Returns
- IReadOnlyList<TResult>
The materialized rows, in result-set order.
Exceptions
- NotSupportedException
The provider cannot return updated rows, or the context is read-only.
ToListAsync(CancellationToken)
Asynchronously executes the update and returns every updated row.
public Task<IReadOnlyList<TResult>> ToListAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancels execution.
Returns
- Task<IReadOnlyList<TResult>>
A task producing the materialized rows, in result-set order.
Exceptions
- NotSupportedException
The provider cannot return updated rows, or the context is read-only.
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
- NotSupportedException
The context is not database-backed (for example the in-memory provider), or the provider cannot return updated rows.