แก้ไข

แชร์ผ่าน


DbBatch Class

Definition

Represents a batch of commands which can be executed against a data source in a single round trip. Provides a base class for database-specific classes that represent command batches.

public ref class DbBatch abstract : IAsyncDisposable, IDisposable
public abstract class DbBatch : IAsyncDisposable, IDisposable
type DbBatch = class
    interface IDisposable
    interface IAsyncDisposable
Public MustInherit Class DbBatch
Implements IAsyncDisposable, IDisposable
Inheritance
DbBatch
Implements

Remarks

The precise semantics of batch execution vary across ADO.NET providers, especially around error handling. When possible, it's recommended that an error in a command within the batch immediately terminate the batch, skip all subsequent commands, and roll back commands that already executed. However, this behavior may not be supported across databases; consult your ADO.NET provider's documentation.

Constructors

DbBatch()

Initializes a new instance of the DbBatch class.

Properties

BatchCommands

Gets the collection of DbBatchCommand objects.

Connection

Gets or sets the DbConnection used by this DbBatch.

DbBatchCommands

When overridden in a derived class, gets the collection of DbBatchCommand objects.

DbConnection

When overridden in a derived class, gets or sets the DbConnection used by this DbBatch.

DbTransaction

When overridden in a derived class, gets or sets the DbTransaction within which this DbBatch object executes.

Timeout

Gets or sets the wait time (in seconds) before terminating the attempt to execute the batch and generating an error.

Transaction

Gets or sets the DbTransaction within which this DbBatch object executes.

Methods

Cancel()

Attempts to cancel the execution of a DbBatch.

CreateBatchCommand()

Creates a new instance of a DbBatchCommand object.

CreateDbBatchCommand()

When overridden in a derived class, creates a new instance of a DbBatchCommand object.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

DisposeAsync()

Asynchronously diposes the batch object.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
ExecuteDbDataReader(CommandBehavior)

When overridden in a derived class, executes the batch against its connection, returning a DbDataReader which can be used to access the results.

ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken)

Providers should implement this method to provide a non-default implementation for ExecuteReader overloads.

The default implementation invokes the synchronous ExecuteReader() method and returns a completed task, blocking the calling thread. The default implementation will return a cancelled task if passed an already cancelled cancellation token. Exceptions thrown by ExecuteReader will be communicated via the returned Task Exception property.

This method accepts a cancellation token that can be used to request the operation to be cancelled early. Implementations may ignore this request.

ExecuteNonQuery()

Executes the batch against its connection object, returning the total number of rows affected across all the batch commands.

ExecuteNonQueryAsync(CancellationToken)

This is the asynchronous version of ExecuteNonQuery(). Providers should override with an appropriate implementation. The cancellation token may optionally be ignored.

The default implementation invokes the synchronous ExecuteNonQuery() method and returns a completed task, blocking the calling thread. The default implementation will return a cancelled task if passed an already cancelled cancellation token. Exceptions thrown by ExecuteNonQuery() will be communicated via the returned Task Exception property.

Do not invoke other methods and properties of the DbCommand object until the returned Task is complete.

ExecuteReader(CommandBehavior)

Executes the batch against its connection, returning a DbDataReader which can be used to access the results.

ExecuteReaderAsync(CancellationToken)

An asynchronous version of ExecuteReader, which executes the batch against its connection, returning a DbDataReader which can be used to access the results.

ExecuteReaderAsync(CommandBehavior, CancellationToken)

An asynchronous version of ExecuteReader, which executes the batch against its connection, returning a DbDataReader which can be used to access the results.

ExecuteScalar()

Executes the batch and returns the first column of the first row in the first returned result set. All other columns, rows and resultsets are ignored.

ExecuteScalarAsync(CancellationToken)

An asynchronous version of ExecuteScalar(), which executes the batch and returns the first column of the first row in the first returned result set. All other columns, rows and result sets are ignored.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Prepare()

Creates a prepared (or compiled) version of the batch, or of each of its commands, on the data source.

PrepareAsync(CancellationToken)

Asynchronously creates a prepared (or compiled) version of the batch, or of each of its commands, on the data source.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Extension Methods

ConfigureAwait(IAsyncDisposable, Boolean)

Configures how awaits on the tasks returned from an async disposable will be performed.

Applies to