首页 > 代码库 > EF 怎么调用存储过程并获得output参数

EF 怎么调用存储过程并获得output参数

1、MVC4的项目,自动会把存储过程在项目中映射为函数。

2、存储过程:

  

 1 ALTER PROCEDURE [dbo].[P_FindAnZhiRen] 2      @tempP_ID int output   3     ,@Member_ID int 4     ,@Is_Right bit  5 AS 6  7  8 set @tempP_ID =@Member_ID  9 BEGIN10 11 12 if @Is_Right =013 begin14     While(Exists(select 1 from tbMemberInfo where Parent_ID=@tempP_ID and Is_Right=0))15     begin16         select @tempP_ID=Member_ID from tbMemberInfo where Parent_ID=@tempP_ID and Is_Right=017     end     18 end 19 20 21 if @Is_Right =122 begin23     if(Exists(select 1 from tbMemberInfo where Parent_ID=@tempP_ID and Is_Right=1))24     begin25         select @tempP_ID=Member_ID from tbMemberInfo where Parent_ID=@tempP_ID and Is_Right=126     end27     28     While(Exists(select 1 from tbMemberInfo where Parent_ID=@tempP_ID and Is_Right=0))29     begin30         select @tempP_ID=Member_ID from tbMemberInfo where Parent_ID=@tempP_ID and Is_Right=031     end     32 end 33 34 END

项目代码:

  

            var tempP_ID = new ObjectParameter("tempP_ID", typeof(Int32));            var result = db.P_FindAnZhiRen(tempP_ID, 1, false );            var result1 = tempP_ID.Value;
result1就是output的值

EF 怎么调用存储过程并获得output参数