Oracle.DataAccess.Client.OracleCommand ExecuteReaderAsync

点点圈 提交于 2019-12-11 12:07:28

问题


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:


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).



来源:https://stackoverflow.com/questions/19598003/oracle-dataaccess-client-oraclecommand-executereaderasync

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!