EntityFramework calling scaler function throws Must declare the scalar variable

0

I have scaler function countAbsence that takes employeeID as input

I call it as below

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

But I get below exception

System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable \"@employeeID\".\r\n
c#
entity-framework
linq
webapi
asked on Stack Overflow Nov 18, 2020 by r_via

1 Answer

0

You should specify the parameters using SqlParameter.

int count = db.Database
              .SqlQuery<int>("SELECT [dbo].[countAbsence](@employeeID)", new SqlParameter("@employeeID", employeeID))
              .FirstOrDefault();
answered on Stack Overflow Nov 18, 2020 by Krishna Muppalla • edited Nov 18, 2020 by Krishna Muppalla

User contributions licensed under CC BY-SA 3.0