Table of Contents

Class ReaderModificationCommandBatch

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

A base class for ModificationCommandBatch implementations that make use of a data reader.

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

public abstract class ReaderModificationCommandBatch : ModificationCommandBatch
Inheritance
ReaderModificationCommandBatch
Derived
Inherited Members

Remarks

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

Constructors

ReaderModificationCommandBatch(ModificationCommandBatchFactoryDependencies, int?)

Creates a new ReaderModificationCommandBatch instance.

protected ReaderModificationCommandBatch(ModificationCommandBatchFactoryDependencies dependencies, int? maxBatchSize = null)

Parameters

dependencies ModificationCommandBatchFactoryDependencies

Service dependencies.

maxBatchSize int?

The maximum batch size. Defaults to 1000.

Properties

AreMoreBatchesExpected

public override bool AreMoreBatchesExpected { get; }

Property Value

bool

Dependencies

Relational provider-specific dependencies for this service.

protected virtual ModificationCommandBatchFactoryDependencies Dependencies { get; }

Property Value

ModificationCommandBatchFactoryDependencies

IsCommandTextEmpty

Whether any SQL has already been added to the batch command text.

protected virtual bool IsCommandTextEmpty { get; }

Property Value

bool

MaxBatchSize

The maximum number of ModificationCommand instances that can be added to a single batch.

protected virtual int MaxBatchSize { get; }

Property Value

int

ModificationCommands

The list of conceptual insert/update/delete ModificationCommandss in the batch.

public override IReadOnlyList<IReadOnlyModificationCommand> ModificationCommands { get; }

Property Value

IReadOnlyList<IReadOnlyModificationCommand>

ParameterValues

Gets the parameter values for the commands in the batch.

protected virtual Dictionary<string, object?> ParameterValues { get; }

Property Value

Dictionary<string, object>

RelationalCommandBuilder

Gets the relational command builder for the commands in the batch.

protected virtual IRelationalCommandBuilder RelationalCommandBuilder { get; }

Property Value

IRelationalCommandBuilder

RequiresTransaction

public override bool RequiresTransaction { get; }

Property Value

bool

ResultSetMappings

The ResultSetMappings for each command in ModificationCommands.

protected virtual IList<ResultSetMapping> ResultSetMappings { get; }

Property Value

IList<ResultSetMapping>

SqlBuilder

Gets the command text builder for the commands in the batch.

protected virtual StringBuilder SqlBuilder { get; }

Property Value

StringBuilder

StoreCommand

The store command generated from this batch when Complete(bool) is called.

protected virtual RawSqlCommand? StoreCommand { get; set; }

Property Value

RawSqlCommand

UpdateSqlGenerator

The update SQL generator.

protected virtual IUpdateSqlGenerator UpdateSqlGenerator { get; }

Property Value

IUpdateSqlGenerator

Methods

AddCommand(IReadOnlyModificationCommand)

Adds Updates the command text for the command at the given position in the ModificationCommands list.

protected virtual void AddCommand(IReadOnlyModificationCommand modificationCommand)

Parameters

modificationCommand IReadOnlyModificationCommand

The command to add.

AddParameter(IColumnModification)

Adds a parameter for the given columnModification to the relational command being built for this batch.

protected virtual void AddParameter(IColumnModification columnModification)

Parameters

columnModification IColumnModification

The column modification for which to add parameters.

AddParameters(IReadOnlyModificationCommand)

Adds parameters for all column modifications in the given modificationCommand to the relational command being built for this batch.

protected virtual void AddParameters(IReadOnlyModificationCommand modificationCommand)

Parameters

modificationCommand IReadOnlyModificationCommand

The modification command for which to add parameters.

Complete(bool)

public override void Complete(bool moreBatchesExpected)

Parameters

moreBatchesExpected bool

Consume(RelationalDataReader)

Consumes the data reader created by Execute(IRelationalConnection).

protected abstract void Consume(RelationalDataReader reader)

Parameters

reader RelationalDataReader

The data reader.

ConsumeAsync(RelationalDataReader, CancellationToken)

Consumes the data reader created by ExecuteAsync(IRelationalConnection, CancellationToken).

protected abstract Task ConsumeAsync(RelationalDataReader reader, CancellationToken cancellationToken = default)

Parameters

reader RelationalDataReader

The data reader.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task

A task that represents the asynchronous operation.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

Execute(IRelationalConnection)

Executes the command generated by this batch against a database using the given connection.

public override void Execute(IRelationalConnection connection)

Parameters

connection IRelationalConnection

The connection to the database to update.

ExecuteAsync(IRelationalConnection, CancellationToken)

Executes the command generated by this batch against a database using the given connection.

public override Task ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken = default)

Parameters

connection IRelationalConnection

The connection to the database to update.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task

A task that represents the asynchronous operation.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

IsValid()

Checks whether the command text is valid.

protected virtual bool IsValid()

Returns

bool

true if the command text is valid; false otherwise.

RollbackLastCommand(IReadOnlyModificationCommand)

Rolls back the last command added. Used when adding a command caused the batch to become invalid (e.g. CommandText too long).

protected virtual void RollbackLastCommand(IReadOnlyModificationCommand modificationCommand)

Parameters

modificationCommand IReadOnlyModificationCommand

SetRequiresTransaction(bool)

Sets whether the batch requires a transaction in order to execute correctly.

protected virtual void SetRequiresTransaction(bool requiresTransaction)

Parameters

requiresTransaction bool

Whether the batch requires a transaction in order to execute correctly.

TryAddCommand(IReadOnlyModificationCommand)

public override bool TryAddCommand(IReadOnlyModificationCommand modificationCommand)

Parameters

modificationCommand IReadOnlyModificationCommand

Returns

bool