问题描述
有没有办法将 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 和具有多个结果集的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!