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

前端 未结 7 1545
再見小時候
再見小時候 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:11

    well, i think this is what you are looking for:

    create procedure sp_calculatesalary
        @employeeId int
    as
        declare @sql nvarchar(max);
        @sql='select salary, username from employee
                where employeeId=' + cast(@employeeId as nvarchar(10));
    
        declare @t table (salary float, username varchar(50));
        insert into @t exec(@sql);
    
        select salary, username from @t;
    return
    

    this will generate a public partial class sp_calculatesalary_Result in entity framework based DAL.

提交回复
热议问题