You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

EF Core调用存储过程提示@soruceCurrencyId参数未提供,如何解决?

问题原因及解决方法

核心问题是参数名拼写不匹配:

  • 存储过程定义的参数是 @soruceCurrencyId(单词拼写错误,少了字母c)
  • 调用代码中传入的参数是 @sourceCurrencyId(正确拼写为source)

SQL Server会严格匹配参数名称,这就导致存储过程找不到预期的@soruceCurrencyId参数,从而抛出错误。

修正步骤

  1. 统一参数名称
    推荐修正存储过程的参数名,使用正确拼写,避免后续调用再出问题:
ALTER PROCEDURE [dbo].[GetCurrencyAtDate]
    @sourceCurrencyId int, -- 修正拼写为source
    @targetCurrencyId int,
    @year int,
    @month int,
    @day int,
    @result decimal OUTPUT
AS
BEGIN
    DECLARE @targetDate DATETIME
    SET @targetDate = DATEADD(DAY, @day - 1, DATEADD(MONTH, @month - 1, DATEADD(YEAR, @year - 1900, 0)))

    SELECT TOP 1 @result = Currency
    FROM KurTable
    WHERE SourceKur = @sourceCurrencyId -- 同步修正此处的参数引用
      AND TargetKur = @targetCurrencyId
      AND Date <= @targetDate
    ORDER BY ABS(DATEDIFF(DAY, Date, @targetDate));
END
  1. 修正输出参数的获取逻辑
    你的代码用ExecuteScalarAsync()获取结果,但存储过程是通过OUTPUT参数返回值的,ExecuteScalar会返回查询的第一行第一列,而此处查询仅做赋值操作,不会返回结果集,正确做法是执行命令后读取输出参数的值:
// 替换原有的ExecuteScalarAsync代码
await command.ExecuteNonQueryAsync();
currencyValue = Convert.ToDecimal(resultParameter.Value);

内容的提问来源于stack exchange,提问作者Musa AKYUZ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 12:10:34