locked
How to get the store-procedure select result in EF RRS feed

  • Question

  • User1052662409 posted

    Hi All,

    Below is my store procedure.

    BEGIN
    UPDATE Request_Master 
    SET totalvalue=@totalvalue
    WHERE bigid=@projectid
    SELECT 'ADD'
    END

    I am executing this store procedure using EF like below.

    [HttpPost]
            public string Update_Total_Value_Request_Payment_Report(string projectid, decimal totalvalue)
            {
                SqlParameter param1 = new SqlParameter("@case", 2);
                SqlParameter param2 = new SqlParameter("@projectid", projectid);
                SqlParameter param3 = new SqlParameter("@totalvalue", totalvalue);
    
                string result = db.Database.SqlQuery<RequestPaymentModel>("usp_request_payment_report_details  @case=@case, @projectid = @projectid,@totalvalue=@totalvalue", param1, param2, param3).ToString();
                return result;
            }

    How can I get 'ADD' test(which I am selecting from store procedure ) as sting after executing the store procedure. 

    Please suggest.

    Wednesday, August 21, 2019 10:34 AM

Answers

  • User475983607 posted

    Hi All,

    Below is my store procedure.

    BEGIN
    UPDATE Request_Master 
    SET totalvalue=@totalvalue
    WHERE bigid=@projectid
    SELECT 'ADD'
    END

    I am executing this store procedure using EF like below.

    [HttpPost]
            public string Update_Total_Value_Request_Payment_Report(string projectid, decimal totalvalue)
            {
                SqlParameter param1 = new SqlParameter("@case", 2);
                SqlParameter param2 = new SqlParameter("@projectid", projectid);
                SqlParameter param3 = new SqlParameter("@totalvalue", totalvalue);
    
                string result = db.Database.SqlQuery<RequestPaymentModel>("usp_request_payment_report_details  @case=@case, @projectid = @projectid,@totalvalue=@totalvalue", param1, param2, param3).ToString();
                return result;
            }

    How can I get 'ADD' test(which I am selecting from store procedure ) as sting after executing the store procedure. 

    Please suggest.

    You've defined the procedure results as RequestPaymentModel.  Therefore you need to return a RequestPaymentModel from the stored procedure.  Executing raw queries in EF is covered in the official documentation.

    https://docs.microsoft.com/en-us/ef/ef6/querying/raw-sql

    Use an OUTPUT parameter to return single values like a string.  Again, this concept is covered in the official documentation.

    https://docs.microsoft.com/en-us/ef/ef6/querying/raw-sql#output-parameters

    https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/retrieving-data-using-a-datareader

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 21, 2019 10:59 AM

All replies

  • User475983607 posted

    Hi All,

    Below is my store procedure.

    BEGIN
    UPDATE Request_Master 
    SET totalvalue=@totalvalue
    WHERE bigid=@projectid
    SELECT 'ADD'
    END

    I am executing this store procedure using EF like below.

    [HttpPost]
            public string Update_Total_Value_Request_Payment_Report(string projectid, decimal totalvalue)
            {
                SqlParameter param1 = new SqlParameter("@case", 2);
                SqlParameter param2 = new SqlParameter("@projectid", projectid);
                SqlParameter param3 = new SqlParameter("@totalvalue", totalvalue);
    
                string result = db.Database.SqlQuery<RequestPaymentModel>("usp_request_payment_report_details  @case=@case, @projectid = @projectid,@totalvalue=@totalvalue", param1, param2, param3).ToString();
                return result;
            }

    How can I get 'ADD' test(which I am selecting from store procedure ) as sting after executing the store procedure. 

    Please suggest.

    You've defined the procedure results as RequestPaymentModel.  Therefore you need to return a RequestPaymentModel from the stored procedure.  Executing raw queries in EF is covered in the official documentation.

    https://docs.microsoft.com/en-us/ef/ef6/querying/raw-sql

    Use an OUTPUT parameter to return single values like a string.  Again, this concept is covered in the official documentation.

    https://docs.microsoft.com/en-us/ef/ef6/querying/raw-sql#output-parameters

    https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/retrieving-data-using-a-datareader

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 21, 2019 10:59 AM
  • User1052662409 posted

    You've defined the procedure results as RequestPaymentModel.  Therefore you need to return a RequestPaymentModel from the stored procedure. 

    Thanks mgebhard Sir.

    Wednesday, August 21, 2019 11:25 AM