Getting output parameter value from SP using EF RRS feed

  • Question

  • Hello Friends

    Here is code that I am using to return the list from the stored procedure.

                     IEnumerable<Assignment> assgn = null
                    SqlParameter output = new SqlParameter("@intTotalRecords", SqlDbType.Int);
                    output.Direction = ParameterDirection.Output;

                    assgn = DbEntities.Database.SqlQuery<Assignment>("usp_MySP_test @AreaCode, output);

                    string test = output.Value.ToString();

    I am facing issue in getting the output parameter value from the stored procedure. I tested the stored procedure using ado.net and was able to get the output parameter but not using EF using the above code.

    Please help

    Monday, November 25, 2013 1:18 PM


  • Hello,

    For retrieving stored procedure output parameters in Entity Framework, I made a sample and please have a look at it below:

    The SP:

    CREATE PROCEDURE [dbo].[TestForOutputSP]
           @param1 int = 0,
           @param2 int output
           SELECT @param2=count(*) from [Order] where [OrderID] = @param1
    RETURN 0

    The Query Codes:

    internal void Execute()
                using (DataBaseFirstDBEntities db = new DataBaseFirstDBEntities())
                    int input = 1;
                    ObjectParameter output = new ObjectParameter("param2", typeof(int));
                    var result = db.TestForOutputSP(input, output);
                    var count = output.Value.ToString();

    The result:

    You can have a try with the way like mine.

    For more information regarding it, please check the blog below:



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Fred Bao Tuesday, December 3, 2013 9:02 AM
    Tuesday, November 26, 2013 1:45 AM