Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dapper execute stored procedure raises ArgumentException about multi-mapping

Tags:

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

These are the parameters that are being passed in:

enter image description here

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:

enter image description here

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

like image 845
Bob Yexley Avatar asked Dec 27 '22 07:12

Bob Yexley


1 Answers

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.

like image 63
Bob Yexley Avatar answered Apr 25 '23 22:04

Bob Yexley