Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Dapper QueryAsync to ValueTuple not mapping correctly

Tags:

c#

c#-7.0

dapper

I'm doing the following query using dapper and C#7 ValueTuples (installed nuget):

await connection.QueryAsync<(int, Guid)>(
                $@"SELECT tenant, pid FROM Table 
                ORDER BY id
                OFFSET {skip} ROWS 
                FETCH NEXT {dbBatchSize} ROWS ONLY");

It returns a list of 0 and Guid.Empty.

If I use only int or only Guid it works ok

I also tried naming the ValueTuple according to the columns in the table:

await connection.QueryAsync<(int tenant, Guid pid)>("...")

Same result.

Anyone has any tip? Thanks in advance!

like image 425
Hugo Rocha Avatar asked Dec 14 '22 21:12

Hugo Rocha


1 Answers

This is a known limitation of dapper. It doesn't support copying a query result into a ValueTuple. There is an open issue on Github requesting support for this.

The OP of that request creating a working example of how it could be done in April and it is currently scheduled for the v2.0 release.

like image 185
David Arno Avatar answered Dec 16 '22 09:12

David Arno