0

This thread gives a number of ways to provide a parameter to a stored procedure.

None of them are working for me.

This works:

this.PayrollContext.Database.SqlQuery<CSRRateEntity>("ord_getCSRRate @csr_num = '4745', @ord_pay_period_id = 784").ToList();

This does not:

return this.PayrollContext.Database.SqlQuery<CSRRateEntity>("Exec ord_getCSRRate @csr_num, @ord_pay_period_id",
            new SqlParameter("csr_num", "4745"),
            new SqlParameter("ord_pay_period_id", 784)
            ).ToList();

The Error message is that parameter is not supplied.

Have tried all the variations I can think of and still get that same error message.

This is using Code First, so no import is required. The SP is found, it is just missing the parameters.

Community
  • 1
  • 1
Greg Gum
  • 33,478
  • 39
  • 162
  • 233

2 Answers2

0

Did you import the stored procedure into the edmx?

In the implementation that we have for the stored procedure it creates parameters like this:

    var inputIdParameter = inputId.HasValue ?
        new ObjectParameter("InputId", inputId) :
        new ObjectParameter("InputId", typeof(int));

The result of the stored procedure function is given like this

return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<T>("[SP_NAME]",  inputIdParameter);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
CheGueVerra
  • 7,849
  • 4
  • 37
  • 49
0

The solution turned out to be to change the order of the parameters in the stored procedure so that optional parameters come after the required parameters (like in c#).

Works:

ALTER procedure [dbo].[ord_GetCSRRate]@ord_pay_period_id int,@csr_num varchar(10) = null, @csr_id int = null, @update_csr_pay_flag bit = 0

Does not work:

ALTER procedure [dbo].[ord_GetCSRRate]@csr_num varchar(10) = null, @ord_pay_period_id int, @csr_id int = null, @update_csr_pay_flag bit = 0, @recursion_flag bit = 0
Greg Gum
  • 33,478
  • 39
  • 162
  • 233