DbCommand.ExecuteScalarAsync DbCommand.ExecuteScalarAsync DbCommand.ExecuteScalarAsync DbCommand.ExecuteScalarAsync Method

定义

实现一个 ExecuteScalar() 的异步版本,但阻塞调用线程时同步返回一个 TaskImplements the asynchronous version of ExecuteScalar(), but returns a Task synchronously, blocking the calling thread.

重载

ExecuteScalarAsync() ExecuteScalarAsync() ExecuteScalarAsync() ExecuteScalarAsync()

ExecuteScalar() 的异步版本,执行查询,并将查询返回的结果集中第一行的第一列返回。An asynchronous version of ExecuteScalar(), which executes the query and returns the first column of the first row in the result set returned by the query. 所有其他的列和行将被忽略。All other columns and rows are ignored.

通过 CancellationToken.None 调用 ExecuteScalarAsync(CancellationToken)Invokes ExecuteScalarAsync(CancellationToken) with CancellationToken.None.

ExecuteScalarAsync(CancellationToken) ExecuteScalarAsync(CancellationToken) ExecuteScalarAsync(CancellationToken)

这是 ExecuteScalar() 的异步版本。This is the asynchronous version of ExecuteScalar(). 提供程序应使用合适的实现进行重写。Providers should override with an appropriate implementation. 可选择性忽略取消标记。The cancellation token may optionally be ignored.

默认实现调用同步 ExecuteScalar() 方法并返回已完成任务,以便阻止调用线程。The default implementation invokes the synchronous ExecuteScalar() 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. ExecuteScalar 引发的异常将通过返回的任务异常属性传递。Exceptions thrown by ExecuteScalar will be communicated via the returned Task Exception property.

在返回的任务完成前,不要调用 DbCommand 对象的其他方法和属性。Do not invoke other methods and properties of the DbCommand object until the returned Task is complete.

注解

有关异步编程的详细信息,请参阅异步编程For more information about asynchronous programming, see Asynchronous Programming.

ExecuteScalarAsync() ExecuteScalarAsync() ExecuteScalarAsync() ExecuteScalarAsync()

ExecuteScalar() 的异步版本,执行查询,并将查询返回的结果集中第一行的第一列返回。An asynchronous version of ExecuteScalar(), which executes the query and returns the first column of the first row in the result set returned by the query. 所有其他的列和行将被忽略。All other columns and rows are ignored.

通过 CancellationToken.None 调用 ExecuteScalarAsync(CancellationToken)Invokes ExecuteScalarAsync(CancellationToken) with CancellationToken.None.

public:
 System::Threading::Tasks::Task<System::Object ^> ^ ExecuteScalarAsync();
public System.Threading.Tasks.Task<object> ExecuteScalarAsync ();
member this.ExecuteScalarAsync : unit -> System.Threading.Tasks.Task<obj>
Public Function ExecuteScalarAsync () As Task(Of Object)

返回

表示异步操作的任务。A task representing the asynchronous operation.

异常

执行命令文本时出现的一个错误。An error occurred while executing the command text.

注解

有关异步编程的详细信息,请参阅异步编程For more information about asynchronous programming, see Asynchronous Programming.

另请参阅

ExecuteScalarAsync(CancellationToken) ExecuteScalarAsync(CancellationToken) ExecuteScalarAsync(CancellationToken)

这是 ExecuteScalar() 的异步版本。This is the asynchronous version of ExecuteScalar(). 提供程序应使用合适的实现进行重写。Providers should override with an appropriate implementation. 可选择性忽略取消标记。The cancellation token may optionally be ignored.

默认实现调用同步 ExecuteScalar() 方法并返回已完成任务,以便阻止调用线程。The default implementation invokes the synchronous ExecuteScalar() 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. ExecuteScalar 引发的异常将通过返回的任务异常属性传递。Exceptions thrown by ExecuteScalar will be communicated via the returned Task Exception property.

在返回的任务完成前,不要调用 DbCommand 对象的其他方法和属性。Do not invoke other methods and properties of the DbCommand object until the returned Task is complete.

public:
 virtual System::Threading::Tasks::Task<System::Object ^> ^ ExecuteScalarAsync(System::Threading::CancellationToken cancellationToken);
public virtual System.Threading.Tasks.Task<object> ExecuteScalarAsync (System.Threading.CancellationToken cancellationToken);
abstract member ExecuteScalarAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<obj>
override this.ExecuteScalarAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<obj>

参数

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

要监视取消请求的标记。The token to monitor for cancellation requests.

返回

表示异步操作的任务。A task representing the asynchronous operation.

异常

执行命令文本时出现的一个错误。An error occurred while executing the command text.

注解

有关异步编程的详细信息,请参阅异步编程For more information about asynchronous programming, see Asynchronous Programming.

另请参阅

适用于