must declare the scalar variable '@custid' using dbcontext.Database.SqlQuery?

前端 未结 2 342
你的背包
你的背包 2021-01-17 11:22

I am trying to execute stored procedure from bcontext.Database.SqlQuery using EF5.

It is throwing an error must declare the scalar variable \'@custid\'<

相关标签:
2条回答
  • 2021-01-17 11:35

    Try

    var results = _MiscContext.Database.SqlQuery<int>(
                  "exec sp_GetStaff {0}",
                  customerNumber).ToList();
    0 讨论(0)
  • 2021-01-17 11:58

    Since you're using named parameters, you have to specify the matching name for the parameter you're passing.

    var results = _MiscContext.Database.SqlQuery<int>(
        "exec sp_GetStaff @custid",
        new SqlParameter("custid", customerNumber)).ToList<int>();
    
    0 讨论(0)
提交回复
热议问题