Dapper执行存储过程引发有关多重映射的ArgumentException [英] Dapper execute stored procedure raises ArgumentException about multi-mapping
问题描述
我有一个要使用Dapper尝试执行的存储过程,该存储过程引发了一个错误,该错误似乎与我要执行的操作无关,尽管我似乎无法弄清楚我的操作
I have a stored procedure that I'm trying to execute using Dapper that is raising an error that doesn't appear to be pertinent to what I'm trying to do, although I can't seem to figure out what I'm doing wrong.
这是我要调用的存储过程的签名:
Here is the signature of the stored procedure that I'm trying to call:
ALTER PROCEDURE [dbo].[stp_UpdateInboundDaf]
@InboundType varchar(255),
@Id bigint,
@UserId bigint,
@DonationID bigint = NULL,
@StatusId int = NULL,
@FinalFlag bit = NULL,
@ValidatedFlag bit = NULL,
@SignedFlag bit = NULL
AS ...
这是我编写的尝试调用该过程的代码:
Here's the code that I've written to try to call the procedure:
_cnx.Query("stp_UpdateInboundDaf", new
{
InboundType = parameters.InboundType,
Id = parameters.Id,
UserId = parameters.UserId,
DonationId = parameters.DonationId,
StatusId = parameters.StatusId,
FinalFlag = parameters.IsFinal,
ValidatedFlag = parameters.Validated,
SignedFlag = parameters.Signed
}, commandType: CommandType.StoredProcedure);
这些是传入的参数:
这是我得到的错误:
使用多重映射API时,如果您具有Id
参数以外的其他键,请确保设置splitOn参数名称:splitOn
"When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id Parameter name: splitOn"
更新
从 SqlMapper.GetDynamicSerializer(IDataRecord reader,int startBound,int length,bool returnNullIfFirstMissing)
方法。错误位置和堆栈跟踪如下:
The error is being raised from the SqlMapper.GetDynamicSerializer(IDataRecord reader, int startBound, int length, bool returnNullIfFirstMissing)
method. Here's the error location and stack trace:
有什么想法吗?
我正在使用最新版的Dapper(我从字面上看只是在Github上克隆了回购协议,并在编写此问题之前将SqlMapper.cs放入我的项目中。)
I'm using the current version of Dapper (I literally just cloned the repo on Github and pulled SqlMapper.cs into my project just before writing up this question).
推荐答案
我弄清楚我的问题在这里。我从字面上也遵循这些示例。我的存储过程没有返回任何值,因此 SqlMapper
试图对不存在的内容进行序列化。我将代码更改为使用 _cnx.Execute(...)
而不是 _cnx.Query(...)
现在一切都很好。
I figured out what my problem was here. I was following the examples too literally. My stored procedure doesn't return any values, so SqlMapper
was trying to serialize something that wasn't there. I changed my code to use _cnx.Execute(...)
instead of _cnx.Query(...)
and everything is working fine now.
这篇关于Dapper执行存储过程引发有关多重映射的ArgumentException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!