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

QueryAsync missing buffered parameter #1239

Closed
vitidev opened this issue Apr 13, 2019 · 10 comments
Closed

QueryAsync missing buffered parameter #1239

vitidev opened this issue Apr 13, 2019 · 10 comments

Comments

@vitidev
Copy link

vitidev commented Apr 13, 2019

I can

db.Query<Person>(sql, parameters, buffered: false)

But I can't

db.QueryAsync<Person>(sql, parameters, buffered: false)

At the same time, the multimap overload of QueryAsync has parameter "buffered"

Task<IEnumerable<TReturn>> QueryAsync<TReturn>(this IDbConnection cnn, string sql, Type[] types, Func<object[], TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true,

@mgravell
Copy link
Member

mgravell commented Apr 13, 2019 via email

@vitidev
Copy link
Author

vitidev commented Apr 13, 2019

@mgravell
Yes. I found
QueryAsync<T>(this IDbConnection cnn, CommandDefinition command)

But it was expected that synchronous and asynchronous versions will have "mirror" signatures. Sometimes you have to convert Query into QueryAsyncand it's very nice when it's enough to add Async(+await) and that is all

as it is only pseudo-async at the moment

That all the same it is good, it is possible not to hold a current thread waiting for the response from a database

when async iterators lands in c# vNext

Async enumerators are good, but a little incomprehensible why you can not do without them like

 var reader = await db.ExecuteAsyncReaderAsync(); // 
 while (await reader.ReadAsync())
 {
       var value = reader.GetChar(0);
 }

 var reader = await db.QueryReaderAsync<Person>();
 while (await reader.MoveNext())
 {
      var value = reader.Current;
 }

Or is it already there and I do not read the documentation well?

@mgravell
Copy link
Member

mgravell commented Apr 13, 2019 via email

@ravimp
Copy link

ravimp commented Feb 10, 2022

@mgravell await foreach is out there now. Any plans to support this now?

@mgravell
Copy link
Member

Plans, yes. What I need is time. Working through some redis and protobuf bits, then I should be able to take a look at Dapper

@ravimp
Copy link

ravimp commented Feb 10, 2022

@mgravell, Dapper has been such a help, I'd like to return the favor. I think I can contribute if someone points me in the right direction. Meanwhile, I got this from an SO post. Do you think it is a reliable workaround until we get an API for it?

using var reader = await connection.ExecuteReaderAsync(query, parameters);
var rowParser = reader.GetRowParser<T>();

while (await reader.ReadAsync()) {
    yield return rowParser(reader);
}

@mgravell
Copy link
Member

add some ConfigureAwait(false) and you're probably pretty close; personally I'm also a bit of a stickler for exhausting the reader, because I've seen TDS faults go unreported if this isn't done, so:

while (await reader.ReadAsync()) {
    yield return rowParser(reader);
}
while (await reader.NextResultAsync()) {}

but: up to you

@SeanFarrow
Copy link

Did this ever get implemented in dapper directly?
I'm at a point where this would be really useful.

Thanks,
Sean.

@PedroFerreira4470
Copy link

any news regarding this?

@mgravell
Copy link
Member

mgravell commented Jun 9, 2023

this feature now essentially provided via #1912

@mgravell mgravell closed this as completed Jun 9, 2023
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.

5 participants