无法从c#类的存储过程中读取输出参数

时间:2015-02-18 12:34:02

标签: c# sql-server asp.net-mvc entity-framework stored-procedures

我有调用存储过程的c#代码;负责从多个表中删除记录。我无法从c#class中的存储过程读取输出参数,虽然我可以在从sql server management studio执行存储过程时读取输出参数。

存储过程

ALTER PROCEDURE [dbo].[DeleteFunctionsNavigation]

 @FunctionID INT,
 @Action_identity INT OUTPUT,
 @ActionInFunction_Count INT OUT,
 @Controller_identity INT OUTPUT,
 @FunctionDeleted INT OUTPUT

  AS
  BEGIN

SET NOCOUNT ON;

SELECT @Action_identity = Navigation_FunctionInAction.ActionID 
FROM Navigation_FunctionInAction
WHERE Navigation_FunctionInAction.Function_ID = @FunctionID

SELECT @ActionInFunction_Count = COUNT(Navigation_FunctionInAction.ActionID) FROM Navigation_FunctionInAction WHERE Navigation_FunctionInAction.ActionID =@Action_identity

SELECT @Controller_identity = Navigation_FunctionInController.ControllerID
FROM Navigation_FunctionInController
WHERE Navigation_FunctionInController.Function_ID = @FunctionID

DELETE FROM Navigation_FunctionHierarchy
WHERE Navigation_FunctionHierarchy.Function_IDs = @FunctionID

DELETE FROM Navigation_FunctionInAction
WHERE Navigation_FunctionInAction.Function_ID = @FunctionID

IF(@ActionInFunction_Count<=1)
Begin

    DELETE FROM Navigation_FunctionAction
    WHERE Navigation_FunctionAction.ActionID = @Action_identity
End

DELETE FROM Navigation_FunctionInController
WHERE Navigation_FunctionInController.ControllerID = @Controller_identity

Delete FROM Navigation_Functions 
WHERE Navigation_Functions.Function_ID = @FunctionID

--Check if deleted function exist... to find if record been deleted or not .. 0 means deleted >0 means not deleted
SELECT @FunctionDeleted = COUNT(Navigation_Functions.FunctionName) FROM Navigation_Functions WHERE Navigation_Functions.Function_ID = @FunctionID

RETURN @FunctionDeleted  
END

c#c​​lass

public void DeleteNavigationFunctionByID(int _FunctionNavigationID)
   {
       using (var dbContext = new FunctionContext())
       {
           List<DeleteFunctionNavigation_SP_Map> _query;

           //int _functionDeleted = -1;

           var Action_identity_out = new SqlParameter("Action_identity", SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output };
           var ActionInFunction_Count_out = new SqlParameter("ActionInFunction_Count", SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output };
           var Controller_identity_out = new SqlParameter("Controller_identity", SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output };
           var FunctionDeleted_out = new SqlParameter("FunctionDeleted", SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output };

           var _functionDeleted = dbContext.Database.SqlQuery<DeleteFunctionNavigation_SP_Map>("exec DeleteFunctionsNavigation @FunctionID, @Action_identity out, @ActionInFunction_Count out, @Controller_identity out, @FunctionDeleted out",
                     new SqlParameter("@FunctionID", _FunctionNavigationID),
                     Action_identity_out,
                     ActionInFunction_Count_out,
                     Controller_identity_out,
                     FunctionDeleted_out
           );
       }
}

0 个答案:

没有答案