简体   繁体   English

C#Dapper QueryAsync到ValueTuple没有正确映射

[英]C# Dapper QueryAsync to ValueTuple not mapping correctly

I'm doing the following query using dapper and C#7 ValueTuples (installed nuget): 我正在使用dapper和C#7 ValueTuples(已安装的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. 它返回0和Guid.Empty的列表。

If I use only int or only Guid it works ok 如果我只使用int或只使用Guid它可以正常工作

I also tried naming the ValueTuple according to the columns in the table: 我还尝试根据表中的列命名ValueTuple:

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

Same result. 结果相同。

Anyone has any tip? 有人有任何提示吗? Thanks in advance! 提前致谢!

This is a known limitation of dapper. 这是小巧玲珑的已知限制。 It doesn't support copying a query result into a ValueTuple. 它不支持将查询结果复制到ValueTuple中。 There is an open issue on Github requesting support for this . Github上有一个未解决的问题,要求对此提供支持

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. 该请求的OP创建了一个如何在4月完成的工作示例,目前计划在v2.0发布。

Dapper seems to support ValueTuple query mappings since v.1.50.4, although the issue David Arno pointed out is still open. Dapper似乎支持自v.1.50.4以来的ValueTuple查询映射,尽管David Arno指出的问题仍然是开放的。 We've been utilizing this feature for a while in our projects. 我们在项目中已经使用了这个功能一段时间了。

I'm unable to find any mentions of added support in release notes either, but I managed to find an example usage of this feature in Dapper's test project. 我也无法在发行说明中找到任何增加支持的提及,但我设法在Dapper的测试项目中找到了此功能的示例用法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM