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 BEGIN 10 11 12 if @Is_Right =0 13 begin 14 While(Exists(select 1 from tbMemberInfo where Parent_ID=@tempP_ID and Is_Right=0)) 15 begin 16 select @tempP_ID=Member_ID from tbMemberInfo where Parent_ID=@tempP_ID and Is_Right=0 17 end 18 end 19 20 21 if @Is_Right =1 22 begin 23 if(Exists(select 1 from tbMemberInfo where Parent_ID=@tempP_ID and Is_Right=1)) 24 begin 25 select @tempP_ID=Member_ID from tbMemberInfo where Parent_ID=@tempP_ID and Is_Right=1 26 end 27 28 While(Exists(select 1 from tbMemberInfo where Parent_ID=@tempP_ID and Is_Right=0)) 29 begin 30 select @tempP_ID=Member_ID from tbMemberInfo where Parent_ID=@tempP_ID and Is_Right=0 31 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的值