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
dependenciesUpdateSqlGeneratorDependenciesParameter 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
commandStringBuilderStringBuilderThe 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
commandStringBuilderStringBuilderThe builder to which the SQL should be appended.
namestringThe name of the table.
schemastringThe table schema, or null to use the default schema.
readOperationsIReadOnlyList<IColumnModification>The operations for column values to be read back.
conditionOperationsIReadOnlyList<IColumnModification>The operations used to generate the
WHEREclause for the delete.appendReturningOneClauseboolWhether 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
commandStringBuilderStringBuilderThe builder to which the SQL should be appended.
namestringThe name of the table.
schemastringThe table schema, or null to use the default schema.
AppendDeleteOperation(StringBuilder, IReadOnlyModificationCommand, int)
public virtual ResultSetMapping AppendDeleteOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition)
Parameters
commandStringBuilderStringBuildercommandIReadOnlyModificationCommandcommandPositionint
Returns
AppendDeleteOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)
public virtual ResultSetMapping AppendDeleteOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition, out bool requiresTransaction)
Parameters
commandStringBuilderStringBuildercommandIReadOnlyModificationCommandcommandPositionintrequiresTransactionbool
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
commandStringBuilderStringBuilderThe builder to which the SQL should be appended.
commandIReadOnlyModificationCommandThe command that represents the delete operation.
commandPositionintThe ordinal of this command in the batch.
requiresTransactionboolReturns 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
commandStringBuilderStringBuilderThe builder to which the SQL should be appended.
namestringThe name of the table.
schemastringThe table schema, or null to use the default schema.
writeOperationsIReadOnlyList<IColumnModification>The operations with the values to insert for each column.
readOperationsIReadOnlyList<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
commandStringBuilderStringBuilderThe builder to which the SQL should be appended.
namestringThe name of the table.
schemastringThe table schema, or null to use the default schema.
operationsIReadOnlyList<IColumnModification>The operations representing the data to be inserted.
AppendInsertOperation(StringBuilder, IReadOnlyModificationCommand, int)
public virtual ResultSetMapping AppendInsertOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition)
Parameters
commandStringBuilderStringBuildercommandIReadOnlyModificationCommandcommandPositionint
Returns
AppendInsertOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)
public virtual ResultSetMapping AppendInsertOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition, out bool requiresTransaction)
Parameters
commandStringBuilderStringBuildercommandIReadOnlyModificationCommandcommandPositionintrequiresTransactionbool
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
commandStringBuilderStringBuilderThe builder to which the SQL should be appended.
commandIReadOnlyModificationCommandThe command that represents the delete operation.
commandPositionintThe ordinal of this command in the batch.
requiresTransactionboolReturns 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
commandStringBuilderStringBuildernamestringschemastring
AppendObtainNextSequenceValueOperation(StringBuilder, string, string?)
public virtual void AppendObtainNextSequenceValueOperation(StringBuilder commandStringBuilder, string name, string? schema)
Parameters
commandStringBuilderStringBuildernamestringschemastring
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
commandStringBuilderStringBuilderThe builder to which the SQL should be appended.
operationsIReadOnlyList<IColumnModification>The operations for column values to be read back.
additionalValuesstringAdditional 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
commandStringBuilderStringBuilderThe builder to which the SQL fragment should be appended.
modificationIColumnModificationThe column modification whose literal should get appended.
tableNamestringThe table name of the column, used when an exception is thrown.
schemastringThe 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
commandStringBuilderStringBuildercommandIReadOnlyModificationCommandcommandPositionintrequiresTransactionbool
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
updateSqlGeneratorHelperISqlGenerationHelperThe update sql generator helper.
columnModificationIColumnModificationThe operation representing the data to be updated.
stringBuilderStringBuilderThe builder to which the SQL should be appended.
namestringThe name of the table.
schemastringThe 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
commandStringBuilderStringBuilderThe builder to which the SQL should be appended.
namestringThe name of the table.
schemastringThe table schema, or null to use the default schema.
writeOperationsIReadOnlyList<IColumnModification>The operations for each column.
readOperationsIReadOnlyList<IColumnModification>The operations for column values to be read back.
conditionOperationsIReadOnlyList<IColumnModification>The operations used to generate the
WHEREclause for the update.appendReturningOneClauseboolWhether 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
commandStringBuilderStringBuilderThe builder to which the SQL should be appended.
namestringThe name of the table.
schemastringThe table schema, or null to use the default schema.
operationsIReadOnlyList<IColumnModification>The operations representing the data to be updated.
AppendUpdateOperation(StringBuilder, IReadOnlyModificationCommand, int)
public virtual ResultSetMapping AppendUpdateOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition)
Parameters
commandStringBuilderStringBuildercommandIReadOnlyModificationCommandcommandPositionint
Returns
AppendUpdateOperation(StringBuilder, IReadOnlyModificationCommand, int, out bool)
public virtual ResultSetMapping AppendUpdateOperation(StringBuilder commandStringBuilder, IReadOnlyModificationCommand command, int commandPosition, out bool requiresTransaction)
Parameters
commandStringBuilderStringBuildercommandIReadOnlyModificationCommandcommandPositionintrequiresTransactionbool
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
commandStringBuilderStringBuilderThe builder to which the SQL should be appended.
commandIReadOnlyModificationCommandThe command that represents the delete operation.
commandPositionintThe ordinal of this command in the batch.
requiresTransactionboolReturns 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
commandStringBuilderStringBuilderThe builder to which the SQL should be appended.
namestringThe name of the table.
schemastringThe table schema, or null to use the default schema.
operationsIReadOnlyList<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
commandStringBuilderStringBuilderThe builder to which the SQL should be appended.
operationsIReadOnlyList<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
commandStringBuilderStringBuilderThe builder to which the SQL should be appended.
operationsIReadOnlyList<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
commandStringBuilderStringBuilderThe builder to which the SQL should be appended.
columnModificationIColumnModificationThe column for which the condition is being generated.
useOriginalValueboolIf 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
commandStringBuilderStringBuilderThe builder to which the SQL should be prepended.