How to return values from a dynamic SQL Stored Procedure to the Entity Framework?

前端 未结 7 1534
再見小時候
再見小時候 2020-12-15 01:49

I have a Stored Procedure which executes some dynamic SQL. I want to use this Stored Procedure in entity framework 4, but when I try to create a complex type the procedure r

7条回答
  •  无人及你
    2020-12-15 02:10

    try this

    CREATE PROCEDURE sp_calculatesalary(@EmployeeId as int)   
    AS
       DECLARE @dynsql VARCHAR(500)=' Salary,Username FROM employee WHERE EmployeeId=@empID'    
       EXEC sp_executesql @dynsql,'@empID INT',@empID=@EmployeeID
       SELECT 1 AS salary,2 AS username
    

    Believe me. That is enough.

    Or you can simply create a complex type based on your query result , and then use collection of the complex type as your query result.

提交回复
热议问题