Dapper.NET 和具有多个结果集的存储过程

2023-10-26数据库问题
2

本文介绍了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.

更新: 好的,它工作正常 - 只要结果集没有.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 返回的单行拆分为两个单独的实体)似乎尚未得到支持(至少似乎没有过载.Read 可以处理多映射).

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 和具有多个结果集的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Mysql目录里的ibtmp1文件过大造成磁盘占满的解决办法
ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致...
2025-01-02 数据库问题
151

按天分组的 SQL 查询
SQL query to group by day(按天分组的 SQL 查询)...
2024-04-16 数据库问题
77

SQL 子句“GROUP BY 1"是什么意思?意思是?
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)...
2024-04-16 数据库问题
62

MySQL groupwise MAX() 返回意外结果
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)...
2024-04-16 数据库问题
13

在 Group By 查询中包含缺失的月份
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)...
2024-04-16 数据库问题
12

为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)...
2024-04-16 数据库问题
13