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
r_via
  • 15
  • 5

1 Answers1

0

You should specify the parameters using SqlParameter.

int count = db.Database
              .SqlQuery<int>("SELECT [dbo].[countAbsence](@employeeID)", new SqlParameter("@employeeID", employeeID))
              .FirstOrDefault();
Krishna Varma
  • 4,238
  • 2
  • 10
  • 25