问题描述
因此,因为OracleCommand类扩展了DbCommand类,所以它实现了Execute方法的异步版本.但是,我无法从Oracle找到支持该方法的对该OracleCommand类的任何引用(我正在使用11g): http://docs.oracle.com/html/E10927_01/OracleCommandClass.htm
So because the OracleCommand class extends the DbCommand class it implements the Async versions of it's Execute methods. However, I cannot find any reference to that OracleCommand class supporting these methods from Oracle (I am using 11g):http://docs.oracle.com/html/E10927_01/OracleCommandClass.htm
有人知道支持这些方法的内幕是什么吗?它们似乎是非阻塞的,并且在使用中支持取消操作(我希望坦白地说是NotImplementedException),但是由于文档的原因,这让我感到不受支持,所以我想确保没有任何麻烦.
Do anyone know what this is doing under the hood to support these methods? They appear to be non-blocking and support cancellation in usage (I expected a NotImplementedException to be honest), but this feels unsupported to me because of the documentation so I want to make sure that there aren't any gotchas.
推荐答案
Oracle客户端不会覆盖方法的异步版本.他们使用默认的DbCommand
实现,这些实现调用方法的非异步版本.
The Oracle client doesn't override the async versions of the methods. They use the default DbCommand
implementnations which call the non-async versions of the methods.
例如,ExecuteNonQueryAsync
的实现是:
// System.Data.Common.DbCommand
public virtual Task<int> ExecuteNonQueryAsync(CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return ADP.CreatedTaskWithCancellation<int>();
}
CancellationTokenRegistration cancellationTokenRegistration = default(CancellationTokenRegistration);
if (cancellationToken.CanBeCanceled)
{
cancellationTokenRegistration = cancellationToken.Register(new Action(this.CancelIgnoreFailure));
}
Task<int> result;
try
{
result = Task.FromResult<int>(this.ExecuteNonQuery());
}
catch (Exception ex)
{
cancellationTokenRegistration.Dispose();
result = ADP.CreatedTaskWithException<int>(ex);
}
return result;
}
如您所见,它只是简单地调用了ExecuteNonQuery
(ExecuteNonQueryAsync
的无参数重载调用了该版本的方法).
As you can see, it simply calls ExecuteNonQuery
under the hood (the no-parameter overload of ExecuteNonQueryAsync
calls this version of the method).
这篇关于Oracle.DataAccess.Client.OracleCommand ExecuteReaderAsync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!