Table of Contents

Class UpdateSqlGenerator

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 SQL RETURNING clause 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 UpdateSqlGenerator : IUpdateSqlGenerator
Inheritance
UpdateSqlGenerator
Implements
Derived
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

UpdateSqlGenerator(UpdateSqlGeneratorDependencies)

Initializes a new instance of the this class.

protected UpdateSqlGenerator(UpdateSqlGeneratorDependencies dependencies)

Parameters

dependencies UpdateSqlGeneratorDependencies

Parameter object containing dependencies for this service.

Properties

Dependencies

Relational provider-specific dependencies for this service.

protected virtual UpdateSqlGeneratorDependencies Dependencies { get; }

Property Value

UpdateSqlGeneratorDependencies

SqlGenerationHelper

Helpers for generating update SQL.

protected virtual ISqlGenerationHelper SqlGenerationHelper { get; }

Property Value

ISqlGenerationHelper

Methods

AppendBatchHeader(StringBuilder)

Appends SQL text that defines the start of a batch.

public virtual void AppendBatchHeader(StringBuilder commandStringBuilder)

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL should be appended.

AppendDeleteCommand(StringBuilder, string, string?, IReadOnlyList<IColumnModification>, IReadOnlyList<IColumnModification>, bool)

Appends a SQL command for deleting a row to the commands being built.

protected virtual void AppendDeleteCommand(StringBuilder commandStringBuilder, string name, string? schema, IReadOnlyList<IColumnModification> readOperations, IReadOnlyList<IColumnModification> conditionOperations, bool appendReturningOneClause = false)

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 for column values to be read back.

conditionOperations IReadOnlyList<IColumnModification>

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

appendReturningOneClause bool

Whether to append an additional constant of 1 to be read back.

AppendDeleteCommandHeader(StringBuilder, string, string?)

Appends a SQL fragment for starting a DELETE.

protected virtual void AppendDeleteCommandHeader(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.

AppendDeleteOperation(StringBuilder, IReadOnlyModificationCommand, int)

public virtual ResultSetMapping AppendDeleteOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition)

Parameters

commandStringBuilder StringBuilder
command IReadOnlyModificationCommand
commandPosition int

Returns

ResultSetMapping

AppendDeleteOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)

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

Parameters

commandStringBuilder StringBuilder
command IReadOnlyModificationCommand
commandPosition int
requiresTransaction bool

Returns

ResultSetMapping

AppendDeleteReturningOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)

Appends SQL for deleting a row to the commands being built, via a DELETE containing a RETURNING clause for concurrency checking.

protected virtual ResultSetMapping AppendDeleteReturningOperation(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.

AppendInsertCommand(StringBuilder, string, string?, IReadOnlyList<IColumnModification>, IReadOnlyList<IColumnModification>)

Appends a SQL command for inserting a row to the commands being built.

protected virtual void AppendInsertCommand(StringBuilder commandStringBuilder, string name, string? schema, IReadOnlyList<IColumnModification> writeOperations, IReadOnlyList<IColumnModification> readOperations)

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.

writeOperations IReadOnlyList<IColumnModification>

The operations with the values to insert for each column.

readOperations IReadOnlyList<IColumnModification>

The operations for column values to be read back.

AppendInsertCommandHeader(StringBuilder, string, string?, IReadOnlyList<IColumnModification>)

Appends a SQL fragment for starting an INSERT.

protected virtual void AppendInsertCommandHeader(StringBuilder commandStringBuilder, string name, string? schema, IReadOnlyList<IColumnModification> operations)

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.

operations IReadOnlyList<IColumnModification>

The operations representing the data to be inserted.

AppendInsertOperation(StringBuilder, IReadOnlyModificationCommand, int)

public virtual ResultSetMapping AppendInsertOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition)

Parameters

commandStringBuilder StringBuilder
command IReadOnlyModificationCommand
commandPosition int

Returns

ResultSetMapping

AppendInsertOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)

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

Parameters

commandStringBuilder StringBuilder
command IReadOnlyModificationCommand
commandPosition int
requiresTransaction bool

Returns

ResultSetMapping

AppendInsertReturningOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)

Appends SQL for inserting a row to the commands being built, via an INSERT containing an optional RETURNING clause to retrieve any database-generated values.

public virtual ResultSetMapping AppendInsertReturningOperation(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.

AppendNextSequenceValueOperation(StringBuilder, string, string?)

public virtual void AppendNextSequenceValueOperation(StringBuilder commandStringBuilder, string name, string? schema)

Parameters

commandStringBuilder StringBuilder
name string
schema string

AppendObtainNextSequenceValueOperation(StringBuilder, string, string?)

public virtual void AppendObtainNextSequenceValueOperation(StringBuilder commandStringBuilder, string name, string? schema)

Parameters

commandStringBuilder StringBuilder
name string
schema string

AppendReturningClause(StringBuilder, IReadOnlyList<IColumnModification>, string?)

Appends a clause used to return generated values from an INSERT or UPDATE statement.

protected virtual void AppendReturningClause(StringBuilder commandStringBuilder, IReadOnlyList<IColumnModification> operations, string? additionalValues = null)

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL should be appended.

operations IReadOnlyList<IColumnModification>

The operations for column values to be read back.

additionalValues string

Additional values to be read back.

AppendSqlLiteral(StringBuilder, IColumnModification, string?, string?)

Appends the literal value for modification to the command being built by commandStringBuilder.

protected static void AppendSqlLiteral(StringBuilder commandStringBuilder, IColumnModification modification, string? tableName, string? schema)

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL fragment should be appended.

modification IColumnModification

The column modification whose literal should get appended.

tableName string

The table name of the column, used when an exception is thrown.

schema string

The schema of the column, used when an exception is thrown.

AppendStoredProcedureCall(StringBuilder, IReadOnlyModificationCommand, int, out bool)

public virtual ResultSetMapping AppendStoredProcedureCall(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition, out bool requiresTransaction)

Parameters

commandStringBuilder StringBuilder
command IReadOnlyModificationCommand
commandPosition int
requiresTransaction bool

Returns

ResultSetMapping

AppendUpdateColumnValue(ISqlGenerationHelper, IColumnModification, StringBuilder, string, string?)

Appends a SQL fragment representing the value that is assigned to a column which is being updated.

protected virtual void AppendUpdateColumnValue(ISqlGenerationHelper updateSqlGeneratorHelper, IColumnModification columnModification, StringBuilder stringBuilder, string name, string? schema)

Parameters

updateSqlGeneratorHelper ISqlGenerationHelper

The update sql generator helper.

columnModification IColumnModification

The operation representing the data to be updated.

stringBuilder 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.

AppendUpdateCommand(StringBuilder, string, string?, IReadOnlyList<IColumnModification>, IReadOnlyList<IColumnModification>, IReadOnlyList<IColumnModification>, bool)

Appends a SQL command for updating a row to the commands being built.

protected virtual void AppendUpdateCommand(StringBuilder commandStringBuilder, string name, string? schema, IReadOnlyList<IColumnModification> writeOperations, IReadOnlyList<IColumnModification> readOperations, IReadOnlyList<IColumnModification> conditionOperations, bool appendReturningOneClause = false)

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.

writeOperations IReadOnlyList<IColumnModification>

The operations for each column.

readOperations IReadOnlyList<IColumnModification>

The operations for column values to be read back.

conditionOperations IReadOnlyList<IColumnModification>

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

appendReturningOneClause bool

Whether to append an additional constant of 1 to be read back.

AppendUpdateCommandHeader(StringBuilder, string, string?, IReadOnlyList<IColumnModification>)

Appends a SQL fragment for starting an UPDATE.

protected virtual void AppendUpdateCommandHeader(StringBuilder commandStringBuilder, string name, string? schema, IReadOnlyList<IColumnModification> operations)

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.

operations IReadOnlyList<IColumnModification>

The operations representing the data to be updated.

AppendUpdateOperation(StringBuilder, IReadOnlyModificationCommand, int)

public virtual ResultSetMapping AppendUpdateOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition)

Parameters

commandStringBuilder StringBuilder
command IReadOnlyModificationCommand
commandPosition int

Returns

ResultSetMapping

AppendUpdateOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)

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

Parameters

commandStringBuilder StringBuilder
command IReadOnlyModificationCommand
commandPosition int
requiresTransaction bool

Returns

ResultSetMapping

AppendUpdateReturningOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)

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

protected virtual ResultSetMapping AppendUpdateReturningOperation(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.

AppendValues(StringBuilder, string, string?, IReadOnlyList<IColumnModification>)

protected virtual void AppendValues(StringBuilder commandStringBuilder, string name, string? schema, IReadOnlyList<IColumnModification> operations)

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.

operations IReadOnlyList<IColumnModification>

The operations for which there are values.

AppendValuesHeader(StringBuilder, IReadOnlyList<IColumnModification>)

Appends a SQL fragment for a VALUES.

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

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL should be appended.

operations IReadOnlyList<IColumnModification>

The operations for which there are values.

AppendWhereClause(StringBuilder, IReadOnlyList<IColumnModification>)

Appends a WHERE clause.

protected virtual void AppendWhereClause(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.

AppendWhereCondition(StringBuilder, IColumnModification, bool)

Appends a WHERE condition for the given column.

protected virtual void AppendWhereCondition(StringBuilder commandStringBuilder, IColumnModification columnModification, bool useOriginalValue)

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL should be appended.

columnModification IColumnModification

The column for which the condition is being generated.

useOriginalValue bool

If true, then the original value will be used in the condition, otherwise the current value will be used.

GenerateNextSequenceValueOperation(string, string?)

public virtual string GenerateNextSequenceValueOperation(string name, string? schema)

Parameters

name string
schema string

Returns

string

GenerateObtainNextSequenceValueOperation(string, string?)

public virtual string GenerateObtainNextSequenceValueOperation(string name, string? schema)

Parameters

name string
schema string

Returns

string

PrependEnsureAutocommit(StringBuilder)

Prepends a SQL command for turning on autocommit mode in the database, in case it is off.

public virtual void PrependEnsureAutocommit(StringBuilder commandStringBuilder)

Parameters

commandStringBuilder StringBuilder

The builder to which the SQL should be prepended.