Dapper execute stored procedure raises ArgumentException about multi-mapping

核能气质少年 提交于 2019-12-23 15:09:16

问题


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);

These are the parameters that are being passed in:

And this is the error I'm getting:

"When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id Parameter name: splitOn"

UPDATE

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:

Any ideas?

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).


回答1:


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.



来源:https://stackoverflow.com/questions/8945006/dapper-execute-stored-procedure-raises-argumentexception-about-multi-mapping

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!