Dapper.NET and stored proc with multiple result sets(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 和具有多个结果集的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Dapper.NET 和具有多个结果集的存储过程
基础教程推荐
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- oracle区分大小写的原因? 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 在多列上分布任意行 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
