Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection.ExecuteReaderAsync returns IDataReader which has no ReadAsync #1140

Closed
jnm2 opened this issue Oct 12, 2018 · 6 comments · Fixed by #1295
Closed

Connection.ExecuteReaderAsync returns IDataReader which has no ReadAsync #1140

jnm2 opened this issue Oct 12, 2018 · 6 comments · Fixed by #1295

Comments

@jnm2
Copy link
Contributor

jnm2 commented Oct 12, 2018

It's currently necessary to cast the returned IDataReader to DbDataReader in order to do anything asynchronous with it:

using (var reader = (DbDataReader)await connection.ExecuteReaderAsync(command).ConfigureAwait(false))
{
    while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
    {
        // ..
    }
}

The extension method takes an IDbConnection, so this makes sense:

https://github.com/StackExchange/Dapper/blob/48f6754ad69c5bc196612ec23f4887062fa87e17/Dapper/SqlMapper.Async.cs#L1116

Would you please define this extension method next to it?

public static Task<DbDataReader> ExecuteReaderAsync(this DbConnection cnn, CommandDefinition command)

That way this code sample just works:

using (var reader = await connection.ExecuteReaderAsync(command).ConfigureAwait(false))
{
    while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
    {
        // ..
    }
}
@thomas-rose
Copy link

+1

@mgravell
Copy link
Member

I see your point, and that's very nice. Would be happy to take that as a PR (probably the quickest way to get it implemented).

This also probably also ties into v2 API refactors, though. I'll start a separate issue for that.

@mgravell
Copy link
Member

cross-ref #1293

@jnm2
Copy link
Contributor Author

jnm2 commented Jul 11, 2019

@mgravell #1293 has a bunch of exciting plans and now I'm really looking forward to v2. In the meantime, I'll definitely work on a PR.

@jnm2
Copy link
Contributor Author

jnm2 commented Jul 12, 2019

I didn't see this at first, but this is a source-breaking change. Explained at #1295.

@jnm2
Copy link
Contributor Author

jnm2 commented Aug 27, 2019

This will be nice, thank you!

@jnm2 jnm2 changed the title connection.ExecuteReaderAsync returns IDataReader which has no ReadAsync Connection.ExecuteReaderAsync returns IDataReader which has no ReadAsync Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants