Dapper 执行存储过程引发有关多重映射的 ArgumentException

发布于 2024-12-28 06:13:37 字数 1345 浏览 0 评论 0原文

我有一个正在尝试使用 Dapper 执行的存储过程,该过程引发了一个错误,该错误似乎与我想要做的事情无关,尽管我似乎无法弄清楚我在做什么错误的。

这是我尝试调用的存储过程的签名:

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

这是我编写的尝试调用该过程的代码:

_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"

UPDATE

该错误是从 SqlMapper.GetDynamicSerializer(IDataRecord reader, int startBound, int length, bool returnNullIfFirstMissing) 方法引发的。这是错误位置和堆栈跟踪:

在此处输入图像描述

任何 我正在使用 Dapper 的当前版本(我实际上只是在 Github 上克隆了存储库,

并在写这个问题之前将 SqlMapper.cs 拉入我的项目中)。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久而酒知 2025-01-04 06:13:37

我明白我的问题出在哪里了。我太从字面上理解了这些例子。我的存储过程不返回任何值,因此 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文