【问题标题】:EntityFramework calling scaler function throws Must declare the scalar variable [duplicate]实体框架调用标量函数抛出必须声明标量变量[重复]
【发布时间】:2020-11-18 12:11:02
【问题描述】:

我有缩放函数countAbsenceemployeeID 作为输入

我这样称呼它

int count = db.Database.SqlQuery<int>("SELECT [dbo].[countAbsence](@employeeID)", employeeID).FirstOrDefault();

但我得到以下异常

System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable \"@employeeID\".\r\n

【问题讨论】:

    标签: c# entity-framework linq webapi


    【解决方案1】:

    您应该使用SqlParameter 指定参数。

    int count = db.Database
                  .SqlQuery<int>("SELECT [dbo].[countAbsence](@employeeID)", new SqlParameter("@employeeID", employeeID))
                  .FirstOrDefault();
    

    【讨论】:

    • countAbsence 不是表,它是一个标量函数。您提出的查询正在尝试查询一个表。
    • 知道了@Flater。我已经更正了帖子
    猜你喜欢
    • 1970-01-01
    • 2018-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-15
    • 1970-01-01
    • 2011-11-03
    • 1970-01-01
    相关资源
    最近更新 更多