Dapper QueryMultiple存储过程,不映射到对象 [英] Dapper QueryMultiple Stored Procedures w/o mapping to Objects

查看:146
本文介绍了Dapper QueryMultiple存储过程,不映射到对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用dapper,我可以对存储过程执行批处理,类似于:

With dapper, I can do batch execute for Stored Procedures, something similar to:

connection.Execute(@"
  exec sp1 @i = @one, @y = @two 
  exec sp2 @i = @three",
  new { one = 1, two = 2, three = 3 });

但是,检索到现在为止我看到的数据的唯一方法是使用

However, the only means of retrieving data that I have seen till now is by using

results.Read<Type>()

如果结果未映射到对象怎么办?例如,我正在编写通用代码以执行具有可变输入/输出参数&结果集。

What if the results don't map to an object? For instance, I am writing "generic" code to execute any SP with variable in/out parameters & result sets.

谢谢

推荐答案

您想要什么API?如果可以单独处理网格,请执行以下操作:

What API do you want? If you can process the grids separately: do that:

using(var multi = connection.QueryMultiple(...))
{
    while(!multi.IsConsumed) {
        // ...
    }
}

其中 ... 可以访问:


  • Read()用于动态行-注意每一行也实现 IDictionary< string,object>

  • Read< T> ()通过泛型输入类型的行

  • Read(Type)用于没有泛型的类型化行

  • Read< DapperRow >()(实际上,这只是 Read< T>() T c $ c>用于实现 Read(),但也许更方便),它提供了对元数据的更多访问

  • Read() for dynamic rows - noting that each row also implements IDictionary<string,object>
  • Read<T>() for typed rows via generics
  • Read(Type) for typed rows without generics
  • Read<DapperRow>() (actually, this is just the T that Read<T>() uses to implement Read(), but perhaps more convenient), which provides slightly more access to metadata

如果您想放到原始的 IDataReader ,请执行以下操作:

If you want to drop to a raw IDataReader, do that:

using(var reader = connection.ExecuteReader(...)) {
    // whatever you want
}

关于参数: DynamicParameters 类提供了更丰富的参数控制访问权限,包括参数方向等。

With regards to parameters: the DynamicParameters class provides much richer access to parameter control, including parameter-direction etc.

这篇关于Dapper QueryMultiple存储过程,不映射到对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆