简体   繁体   English

在Petapoco或Dapper中处理不同数量的结果集?

[英]Handling varying number of result sets in Petapoco or Dapper?

I have used QueryMultiple before for handling multiple result sets, but I knew the exact number of result sets being returned. 我之前使用QueryMultiple处理多个结果集,但我知道返回的结果集的确切数量。 In this case, when I call a stored proc with QueryMultiple , the number of result sets returned varies. 在这种情况下,当我使用QueryMultiple调用存储的proc时,返回的结果集的数量会有所不同。 Is it possible to handle this in PetaPoco or another orm such as Dapper? 是否可以在PetaPoco或Dapper等其他组织中处理此问题?

Dapper's QueryMultiple method returns a GridReader ; Dapper的QueryMultiple方法返回GridReader ; a GridReader has a .IsConsumed property that should change to true when you've read all the available result sets, so that might work: GridReader具有.IsConsumed属性,当您阅读所有可用的结果集时,该属性应更改为true ,这样可能会起作用:

using(var reader = conn.QueryMultiple(...)) {
    do {
        var data = reader.Read<...>().AsList();
        // ...
    } while(!reader.IsConsumed);
}

Alternatively, Dapper has an ExecuteReader method that just does the "pack the parameters and invoke step", and a GetTypeDeserializer method that exposes just the "materialize a row into an object" code, so you could manually combine those, ie: 另外,Dapper有一个ExecuteReader方法, ExecuteReader执行“打包参数并调用步骤”,还有一个GetTypeDeserializer方法, GetTypeDeserializer公开“将行具体化为对象”代码,因此您可以手动组合它们,即:

using(var reader = conn.ExecuteReader(...)) {
    do {
        var parser = SqlMapper.GetTypeDeserializer(...);
        while(reader.Read()) {
            var obj = parser(reader);
            // ...
        }
    } while(reader.NextResult());
}

(I don't know much about petapoco, sorry) (我对petapoco不太了解,对不起)

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

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