locked
Code First EF : executing stored procedure RRS feed

  • Question

  • User-1129879462 posted

    I am getting this error message:
    The data reader has more than one field. Multiple fields are not valid for EDM primitive or enumeration types

    The stored procedure takes three parameters, two of them being varchar and the last being int

    All the parameters have values, when I execute stored procedure manually with the same values it ran successfully.

    var output = Context.DbQuerySingle<string>(query, sqlParams.ToArray());

    Thursday, February 16, 2017 3:10 PM

Answers

  • User753101303 posted

    Even if the message is misleading have you tried to fix that ?

    When seeing a DbQuerySingle<string> call I would expect that the SP should return a single row and a single column so that the return value can be populated. Or are you using some other mechanism?

    Or if you don't expect to get a value from this SP, you should likely call another method (seems to be your own helpers ?). For now it seems really to me that the SP just doesn't return what the db access API you are using is expecting (rather than being a problem with the parameters you are passing).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 16, 2017 5:15 PM
  • User-1129879462 posted

    I made the stored proc to return something and this has fixed the issue!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 16, 2017 6:05 PM

All replies

  • User753101303 posted

    Hi,

    The error message seems to tell that your query return multiple columns when a single column is expected (also it needs to return a single row).

    When testing your SP manually how many columns does it return?

    Thursday, February 16, 2017 3:30 PM
  • User-1129879462 posted

    The stored proc does not return anything!

    Thursday, February 16, 2017 5:01 PM
  • User753101303 posted

    Even if the message is misleading have you tried to fix that ?

    When seeing a DbQuerySingle<string> call I would expect that the SP should return a single row and a single column so that the return value can be populated. Or are you using some other mechanism?

    Or if you don't expect to get a value from this SP, you should likely call another method (seems to be your own helpers ?). For now it seems really to me that the SP just doesn't return what the db access API you are using is expecting (rather than being a problem with the parameters you are passing).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 16, 2017 5:15 PM
  • User-1129879462 posted

    I made the stored proc to return something and this has fixed the issue!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 16, 2017 6:05 PM