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
UpdateSqlGeneratorDependenciesParameter object containing dependencies for this service.
Properties
Dependencies
Relational provider-specific dependencies for this service.
protected virtual UpdateSqlGeneratorDependencies Dependencies { get; }
Property Value
SqlGenerationHelper
Helpers for generating update SQL.
protected virtual ISqlGenerationHelper SqlGenerationHelper { get; }
Property Value
Methods
AppendBatchHeader(StringBuilder)
Appends SQL text that defines the start of a batch.
public virtual void AppendBatchHeader(StringBuilder commandStringBuilder)
Parameters
commandStringBuilder
StringBuilderThe 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
StringBuilderThe builder to which the SQL should be appended.
name
stringThe name of the table.
schema
stringThe 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
boolWhether 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
StringBuilderThe builder to which the SQL should be appended.
name
stringThe name of the table.
schema
stringThe 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
StringBuildercommand
IReadOnlyModificationCommandcommandPosition
int
Returns
AppendDeleteOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)
public virtual ResultSetMapping AppendDeleteOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition, out bool requiresTransaction)
Parameters
commandStringBuilder
StringBuildercommand
IReadOnlyModificationCommandcommandPosition
intrequiresTransaction
bool
Returns
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
StringBuilderThe builder to which the SQL should be appended.
command
IReadOnlyModificationCommandThe command that represents the delete operation.
commandPosition
intThe ordinal of this command in the batch.
requiresTransaction
boolReturns 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
StringBuilderThe builder to which the SQL should be appended.
name
stringThe name of the table.
schema
stringThe 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
StringBuilderThe builder to which the SQL should be appended.
name
stringThe name of the table.
schema
stringThe 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
StringBuildercommand
IReadOnlyModificationCommandcommandPosition
int
Returns
AppendInsertOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)
public virtual ResultSetMapping AppendInsertOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition, out bool requiresTransaction)
Parameters
commandStringBuilder
StringBuildercommand
IReadOnlyModificationCommandcommandPosition
intrequiresTransaction
bool
Returns
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
StringBuilderThe builder to which the SQL should be appended.
command
IReadOnlyModificationCommandThe command that represents the delete operation.
commandPosition
intThe ordinal of this command in the batch.
requiresTransaction
boolReturns 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
StringBuildername
stringschema
string
AppendObtainNextSequenceValueOperation(StringBuilder, string, string?)
public virtual void AppendObtainNextSequenceValueOperation(StringBuilder commandStringBuilder, string name, string? schema)
Parameters
commandStringBuilder
StringBuildername
stringschema
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
StringBuilderThe builder to which the SQL should be appended.
operations
IReadOnlyList<IColumnModification>The operations for column values to be read back.
additionalValues
stringAdditional 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
StringBuilderThe builder to which the SQL fragment should be appended.
modification
IColumnModificationThe column modification whose literal should get appended.
tableName
stringThe table name of the column, used when an exception is thrown.
schema
stringThe 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
StringBuildercommand
IReadOnlyModificationCommandcommandPosition
intrequiresTransaction
bool
Returns
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
ISqlGenerationHelperThe update sql generator helper.
columnModification
IColumnModificationThe operation representing the data to be updated.
stringBuilder
StringBuilderThe builder to which the SQL should be appended.
name
stringThe name of the table.
schema
stringThe 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
StringBuilderThe builder to which the SQL should be appended.
name
stringThe name of the table.
schema
stringThe 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
boolWhether 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
StringBuilderThe builder to which the SQL should be appended.
name
stringThe name of the table.
schema
stringThe 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
StringBuildercommand
IReadOnlyModificationCommandcommandPosition
int
Returns
AppendUpdateOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)
public virtual ResultSetMapping AppendUpdateOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition, out bool requiresTransaction)
Parameters
commandStringBuilder
StringBuildercommand
IReadOnlyModificationCommandcommandPosition
intrequiresTransaction
bool
Returns
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
StringBuilderThe builder to which the SQL should be appended.
command
IReadOnlyModificationCommandThe command that represents the delete operation.
commandPosition
intThe ordinal of this command in the batch.
requiresTransaction
boolReturns 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>)
Appends values after a AppendValuesHeader(StringBuilder, IReadOnlyList<IColumnModification>) call.
protected virtual void AppendValues(StringBuilder commandStringBuilder, string name, string? schema, IReadOnlyList<IColumnModification> operations)
Parameters
commandStringBuilder
StringBuilderThe builder to which the SQL should be appended.
name
stringThe name of the table.
schema
stringThe 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
StringBuilderThe 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
StringBuilderThe 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
StringBuilderThe builder to which the SQL should be appended.
columnModification
IColumnModificationThe column for which the condition is being generated.
useOriginalValue
boolIf 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
Returns
GenerateObtainNextSequenceValueOperation(string, string?)
public virtual string GenerateObtainNextSequenceValueOperation(string name, string? schema)
Parameters
Returns
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
StringBuilderThe builder to which the SQL should be prepended.