Dapper.NET和具有多个结果集的存储过程 [英] Dapper.NET and stored proc with multiple result sets

查看:208
本文介绍了Dapper.NET和具有多个结果集的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将Dapper.NET与返回多个结果集的存储过程一起使用?

Is there any way to use Dapper.NET with stored procs that return multiple result sets?

对于我来说,第一个结果集是带有单列如果 0 表示调用成功,则第二个结果集将包含实际的数据行/列。 (如果它不为零,则会发生错误,并且不会提供第二个结果集)。

In my case, the first result set is a single row with a single column; if it's 0 then the call was successful, and the second result set will contain that actual rows/columns of data. (and if it was non-zero, an error occured and no second result set will be provided)

是否有任何机会使用Dapper.NET处理此问题?到目前为止,我只得到了那个 0 -但仅此而已。

Any chance to handle this with Dapper.NET? So far, I'm only ever getting back that single 0 - but nothing more.

更新:好,只要结果集为No,就可以正常工作。 2是单个实体:

Update: OK, it works fine - as long as the result set no. 2 is a single entity:

Dapper.SqlMapper.GridReader reader = 
    _conn.QueryMultiple("sprocname", dynParams, 
    commandType: CommandType.StoredProcedure);

int status = reader.Read<int>().FirstOrDefault();
MyEntityType resultObj = reader.Read<MyEntityType>().FirstOrDefault();

现在,我有另一个要求。

Dapper的多重映射(将SQL Server返回的单行拆分为两个单独的实体)目前似乎还不支持第二个结果集(至少不支持)似乎是的重载。阅读< T> 可以处理多重映射)。

Dapper's multi-mapping (splitting up a single row returned from SQL Server into two separate entities) for that second result set doesn't seem to be supported as of yet (at least there doesn't seem to be an overload of .Read<T> that can handle multi-mapping).

我该如何将该行分为两个实体?

How can I get split that row into two entities?

推荐答案

您是否尝试过 QueryMultiple 方法?它说应该这样:

Have you tried the QueryMultiple method? It says it should:


执行一个返回
多个结果集的命令,并依次访问每个

Execute a command that returns multiple result sets, and access each in turn

您需要添加using语句才能启用QueryMultiple。

You'll need to add this using statement to enable QueryMultiple .

using Dapper; /* to add extended method QueryMultiple public static GridReader QueryMultiple(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null); */

这篇关于Dapper.NET和具有多个结果集的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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