Stored Procedure returns incorrect scalar value of -1, instead of return value

后端 未结 4 684
日久生厌
日久生厌 2021-01-02 20:36

I am trying to return a scalar value from a stored procedure. I actually want to return the ID of a newly created record, but I have simplified my problem down to a stored p

4条回答
  •  粉色の甜心
    2021-01-02 21:08

    to solve this entity framework issue and assuming you already have a stored procedure working and you don't want to fix the places where it works good using other ways then EF you can replace the:

    RETURN(0)
    

    with:

    BEGIN
        SELECT(0)
        RETURN(0)
    END
    

    that is if its a part of an IF sentence,
    theמ go to: EF model (.edmx) -> Model Browser -> Function Imports -> (doubl click your func) ->Scalars -> Int32

    now your return value is:

    ObjectResult>
    

    you can receive it by writing:

    int? response = 0;
    response = myEntity.myStoredProcedure(var1, var2).FirstOrDefault();
    

    or in pics:
    1.
    Model Browser
    2.
    Function Imports
    3.
    Scalars

    doing all this makes the EF model (.edmx) also supporting the 'Update Model from Database...' and you can update it without worry to changes you just made.

提交回复
热议问题