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

Constructors

ReaderModificationCommandBatch(ModificationCommandBatchFactoryDependencies)

Creates a new ReaderModificationCommandBatch instance.

protected ReaderModificationCommandBatch(ModificationCommandBatchFactoryDependencies dependencies)

Parameters

dependencies ModificationCommandBatchFactoryDependencies

Service dependencies.

Properties

CachedCommandText

Gets or sets the cached command text for the commands in the batch.

protected virtual StringBuilder CachedCommandText { get; set; }

Property Value

StringBuilder

CommandResultSet

The ResultSetMappings for each command in ModificationCommands.

protected virtual IList<ResultSetMapping> CommandResultSet { get; }

Property Value

IList<ResultSetMapping>

Dependencies

Service dependencies.

public virtual ModificationCommandBatchFactoryDependencies Dependencies { get; }

Property Value

ModificationCommandBatchFactoryDependencies

LastCachedCommandIndex

The ordinal of the last command for which command text was built.

protected virtual int LastCachedCommandIndex { get; set; }

Property Value

int

ModificationCommands

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

public override IReadOnlyList<ModificationCommand> ModificationCommands { get; }

Property Value

IReadOnlyList<ModificationCommand>

UpdateSqlGenerator

The update SQL generator.

protected virtual IUpdateSqlGenerator UpdateSqlGenerator { get; }

Property Value

IUpdateSqlGenerator

Methods

AddCommand(ModificationCommand)

Adds the given insert/update/delete ModificationCommands to the batch.

public override bool AddCommand(ModificationCommand modificationCommand)

Parameters

modificationCommand ModificationCommand

The command to add.

Returns

bool

true if the command was successfully added; false if there was no room in the current batch to add the command and it must instead be added to a new batch.

CanAddCommand(ModificationCommand)

Checks whether or not a new command can be added to the batch.

protected abstract bool CanAddCommand(ModificationCommand modificationCommand)

Parameters

modificationCommand ModificationCommand

The command to potentially add.

Returns

bool

true if the command can be added; false otherwise.

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.

CreateStoreCommand()

Generates a RawSqlCommand for the batch.

protected virtual RawSqlCommand CreateStoreCommand()

Returns

RawSqlCommand

The command.

CreateValueBufferFactory(IReadOnlyList<ColumnModification>)

Creates the IRelationalValueBufferFactory that will be used for creating a Microsoft.EntityFrameworkCore.Storage.ValueBuffer to consume the data reader.

protected virtual IRelationalValueBufferFactory CreateValueBufferFactory(IReadOnlyList<ColumnModification> columnModifications)

Parameters

columnModifications IReadOnlyList<ColumnModification>

The list of ColumnModifications for all the columns being modified such that a ValueBuffer with appropriate slots can be created.

Returns

IRelationalValueBufferFactory

The factory.

Execute(IRelationalConnection)

Executes the command generated by CreateStoreCommand() 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 CreateStoreCommand() 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.

GetCommandText()

Gets the command text for all the commands in the current batch and also caches it on CachedCommandText.

protected virtual string GetCommandText()

Returns

string

The command text.

GetParameterCount()

Gets the total number of parameters needed for the batch.

protected virtual int GetParameterCount()

Returns

int

The total parameter count.

IsCommandTextValid()

Checks whether or not the command text is valid.

protected abstract bool IsCommandTextValid()

Returns

bool

true if the command text is valid; false otherwise.

ResetCommandText()

Resets the builder to start building a new batch.

protected virtual void ResetCommandText()

UpdateCachedCommandText(int)

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

protected virtual void UpdateCachedCommandText(int commandPosition)

Parameters

commandPosition int

The position of the command to generate command text for.