Table of Contents

Class UpdateAndSelectSqlGenerator

Namespace
Microsoft.EntityFrameworkCore.Update
Assembly
Microsoft.EntityFrameworkCore.Relational.dll

A base class for the IUpdateSqlGenerator service that is typically inherited from by database providers. The implementation uses a separate SELECT query after the update SQL to retrieve any database-generated values or for concurrency checking.

This type is typically used by database providers; it is generally not used in application code.

public abstract class UpdateAndSelectSqlGenerator : UpdateSqlGenerator, IUpdateSqlGenerator
Inheritance
UpdateAndSelectSqlGenerator
Implements
Inherited Members

Remarks

The service lifetime is Singleton. This means a single instance is used by many Microsoft.EntityFrameworkCore.DbContext instances. The implementation must be thread-safe. This service cannot depend on services registered as Scoped.

See Implementation of database providers and extensions for more information and examples.

Constructors

UpdateAndSelectSqlGenerator(UpdateSqlGeneratorDependencies)

Initializes a new instance of the this class.

protected UpdateAndSelectSqlGenerator(UpdateSqlGeneratorDependencies dependencies)

Parameters

dependencies UpdateSqlGeneratorDependencies

Parameter object containing dependencies for this service.

Methods

AppendDeleteAndSelectOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)

Appends SQL for updating a row to the commands being built, via a DELETE followed by a SELECT for concurrency checking.

protected virtual ResultSetMapping AppendDeleteAndSelectOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition, out bool requiresTransaction)

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL should be appended.

command IReadOnlyModificationCommand

The command that represents the delete operation.

commandPosition int

The ordinal of this command in the batch.

requiresTransaction bool

Returns whether the SQL appended must be executed in a transaction to work correctly.

Returns

ResultSetMapping

The ResultSetMapping for the command.

AppendDeleteOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)

public override ResultSetMapping AppendDeleteOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition, out bool requiresTransaction)

Parameters

commandStringBuilder StringBuilder
command IReadOnlyModificationCommand
commandPosition int
requiresTransaction bool

Returns

ResultSetMapping

AppendFromClause(StringBuilder, string, string?)

Appends a SQL fragment for starting a FROM clause.

protected virtual void AppendFromClause(StringBuilder commandStringBuilder, string name, string? schema)

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL should be appended.

name string

The name of the table.

schema string

The table schema, or null to use the default schema.

AppendIdentityWhereCondition(StringBuilder, IColumnModification)

Appends a WHERE condition for the identity (i.e. key value) of the given column.

protected abstract void AppendIdentityWhereCondition(StringBuilder commandStringBuilder, IColumnModification columnModification)

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL should be appended.

columnModification IColumnModification

The column for which the condition is being generated.

AppendInsertAndSelectOperations(StringBuilder, IReadOnlyModificationCommand, int, out bool)

Appends SQL for inserting a row to the commands being built, via an INSERT followed by an optional SELECT to retrieve any database-generated values.

protected virtual ResultSetMapping AppendInsertAndSelectOperations(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition, out bool requiresTransaction)

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL should be appended.

command IReadOnlyModificationCommand

The command that represents the delete operation.

commandPosition int

The ordinal of this command in the batch.

requiresTransaction bool

Returns whether the SQL appended must be executed in a transaction to work correctly.

Returns

ResultSetMapping

The ResultSetMapping for the command.

AppendInsertOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)

public override ResultSetMapping AppendInsertOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition, out bool requiresTransaction)

Parameters

commandStringBuilder StringBuilder
command IReadOnlyModificationCommand
commandPosition int
requiresTransaction bool

Returns

ResultSetMapping

AppendRowsAffectedWhereCondition(StringBuilder, int)

Appends a WHERE condition checking rows affected.

protected abstract void AppendRowsAffectedWhereCondition(StringBuilder commandStringBuilder, int expectedRowsAffected)

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL should be appended.

expectedRowsAffected int

The expected number of rows affected.

AppendSelectAffectedCommand(StringBuilder, string, string?, IReadOnlyList<IColumnModification>, IReadOnlyList<IColumnModification>, int)

Appends a SQL command for selecting affected data.

protected virtual ResultSetMapping AppendSelectAffectedCommand(StringBuilder commandStringBuilder, string name, string? schema, IReadOnlyList<IColumnModification> readOperations, IReadOnlyList<IColumnModification> conditionOperations, int commandPosition)

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL should be appended.

name string

The name of the table.

schema string

The table schema, or null to use the default schema.

readOperations IReadOnlyList<IColumnModification>

The operations representing the data to be read.

conditionOperations IReadOnlyList<IColumnModification>

The operations used to generate the WHERE clause for the select.

commandPosition int

The ordinal of the command for which rows affected it being returned.

Returns

ResultSetMapping

The ResultSetMapping for this command.

AppendSelectAffectedCountCommand(StringBuilder, string, string?, int)

Appends a SQL command for selecting the number of rows affected.

protected abstract ResultSetMapping AppendSelectAffectedCountCommand(StringBuilder commandStringBuilder, string name, string? schema, int commandPosition)

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL should be appended.

name string

The name of the table.

schema string

The table schema, or null to use the default schema.

commandPosition int

The ordinal of the command for which rows affected it being returned.

Returns

ResultSetMapping

The ResultSetMapping for this command.

AppendSelectCommandHeader(StringBuilder, IReadOnlyList<IColumnModification>)

Appends a SQL fragment for starting a SELECT.

protected virtual void AppendSelectCommandHeader(StringBuilder commandStringBuilder, IReadOnlyList<IColumnModification> operations)

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL should be appended.

operations IReadOnlyList<IColumnModification>

The operations representing the data to be read.

AppendUpdateAndSelectOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)

Appends SQL for updating a row to the commands being built, via an UPDATE followed by a SELECT to retrieve any database-generated values or for concurrency checking.

protected virtual ResultSetMapping AppendUpdateAndSelectOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition, out bool requiresTransaction)

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL should be appended.

command IReadOnlyModificationCommand

The command that represents the delete operation.

commandPosition int

The ordinal of this command in the batch.

requiresTransaction bool

Returns whether the SQL appended must be executed in a transaction to work correctly.

Returns

ResultSetMapping

The ResultSetMapping for the command.

AppendUpdateOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)

public override ResultSetMapping AppendUpdateOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition, out bool requiresTransaction)

Parameters

commandStringBuilder StringBuilder
command IReadOnlyModificationCommand
commandPosition int
requiresTransaction bool

Returns

ResultSetMapping

AppendWhereAffectedClause(StringBuilder, IReadOnlyList<IColumnModification>)

Appends a WHERE clause involving rows affected.

protected virtual void AppendWhereAffectedClause(StringBuilder commandStringBuilder, IReadOnlyList<IColumnModification> operations)

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL should be appended.

operations IReadOnlyList<IColumnModification>

The operations from which to build the conditions.

IsIdentityOperation(IColumnModification)

Returns a value indicating whether the given modification represents an auto-incrementing column.

protected virtual bool IsIdentityOperation(IColumnModification modification)

Parameters

modification IColumnModification

The column modification.

Returns

bool

true if the given modification represents an auto-incrementing column.