varchar out参数导致实体框架问题将数据类型varchar转换为int

时间:2018-07-18 18:29:08

标签: c# sql-server entity-framework

我在使用out参数时遇到问题,该参数返回@SecurityGroup varchar(100)的值是'admin',这是唯一一个从sp引发错误的out参数,其他参数正在工作。错误是

  

将数据类型varchar转换为int时出错

为什么会尝试将varchar转换为int?

ALTER PROCEDURE [LDR].[usp_UI_GetUserProfile] 
    @User VARCHAR(50),
    @MatchTypeID INT, 
    @SecurityGroup VARCHAR(100) OUTPUT, 
    @NumofRowsAllowed INT OUTPUT, 
    @ReturnStatus INT OUTPUT, 
    @ReturnErrorMessage NVARCHAR(4000) OUTPUT

实体框架调用

var parameters = new[] {
                new SqlParameter("@User", UserID){Direction = System.Data.ParameterDirection.Input},
                new SqlParameter("@MatchTypeID", MatchTypeID){Direction = System.Data.ParameterDirection.Input},
                new SqlParameter("@SecurityGroup", DbType.String){Direction = System.Data.ParameterDirection.Output},
                new SqlParameter("@NumofRowsAllowed", DbType.Int32){Direction = System.Data.ParameterDirection.Output},
                new SqlParameter("@ReturnStatus", DbType.Int32){Direction = System.Data.ParameterDirection.Output},
                new SqlParameter("@ReturnErrorMessage", DbType.String){Direction = System.Data.ParameterDirection.Output}
            };

var results = db.Database.ExecuteSqlCommand("exec [LDR].[usp_UI_GetUserProfile] @UserNetID, @MatchTypeID, @SecurityGroup out, @NumofRowsAllowed out, @ReturnStatus out, @ReturnErrorMessage out", parameters[0], parameters[1], parameters[2], parameters[3], parameters[4], parameters[5]);

1 个答案:

答案 0 :(得分:0)

将其包装在try catch块中并在catch语句上抛出断点可能很简单。如果这样做,您可以看到VS尝试执行的操作是错误的