Oracle.DataAccess.Client.OracleCommand ExecuteRead

2019-08-05 06:56发布

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

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.

1条回答
家丑人穷心不美
2楼-- · 2019-08-05 07:24

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.

For example, the implementation of ExecuteNonQueryAsync is:

// 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;
}

As you can see, it simply calls ExecuteNonQuery under the hood (the no-parameter overload of ExecuteNonQueryAsync calls this version of the method).

查看更多
登录 后发表回答