Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SQL Server输出参数在EF C中显示空值#_C#_Sql_Asp.net Mvc_Entity Framework_Output Parameter - Fatal编程技术网

C# SQL Server输出参数在EF C中显示空值#

C# SQL Server输出参数在EF C中显示空值#,c#,sql,asp.net-mvc,entity-framework,output-parameter,C#,Sql,Asp.net Mvc,Entity Framework,Output Parameter,我有一个下面带有输出参数的存储过程 ALTER proc [dbo].[CRS_GetNewMessageCount] @CaseId int, @Type varchar(50), @Location varchar(50), @Count int out as begin if @location='admin' begin if @type='consumer' select @Count=(Select count(fdId) from tb_CRS_Messa

我有一个下面带有输出参数的存储过程

ALTER proc [dbo].[CRS_GetNewMessageCount]
@CaseId int,
@Type varchar(50),
@Location varchar(50),
@Count int out
as

begin
if @location='admin'
    begin
    if @type='consumer'
    select @Count=(Select count(fdId) from tb_CRS_Messages where fdCaseId=@CaseId and fdIsConsumerType=1 and fdIsReadatAdmin=0)
    else
    select @Count=(Select count(fdId) from tb_CRS_Messages where fdCaseId=@CaseId and fdIsMemberType=1 and fdIsReadatAdmin=0)
    end
else
begin
    if @type='consumer'
    select @Count=(Select count(fdId) from tb_CRS_Messages where fdCaseId=@CaseId and fdIsConsumerType=1 and fdIsReadatFront=0)
else
select @Count=(Select count(fdId) from tb_CRS_Messages where fdCaseId=@CaseId and fdIsMemberType=1 and fdIsReadatFront=0)
END
SELECT @Count
END
在SQL server上工作非常完美,请参见以下输出:

我通过
实体框架
调用这个
存储过程

using (DbContext db = new DbContext())
            {
                try
                {
                    var NewMessage = new ObjectParameter("Count", typeof(int));
                    int returnValue = 0;
                    db.CRS_GetNewMessageCount(CaseId, type, location, NewMessage);
                    int.TryParse(NewMessage.Value.ToString(), out returnValue);
                    return returnValue;
                }
                catch { return 0; }
            }
它在输出参数中给出
null


请提供帮助。

不确定这是否有区别,但您是否尝试使用“typeof(Int32)”而不是“typeof(int)”?还可以尝试将NewMessage作为ObjectParameter而不是var,也许这会有所不同

ObjectParameter NewMessage = new ObjectParameter("NewMessage ", typeof(Int32));

您是否尝试在没有参数的情况下运行存储过程,即无论输入什么参数,都返回带有值的@Count变量?这样,您就可以确定输入参数是否错误(由C#移交)。

不确定这是否有区别,但您是否尝试使用“typeof(Int32)”而不是“typeof(int)”?还可以尝试将NewMessage作为ObjectParameter而不是var,也许这会有所不同

ObjectParameter NewMessage = new ObjectParameter("NewMessage ", typeof(Int32));
您是否尝试在没有参数的情况下运行存储过程,即无论输入什么参数,都返回带有值的@Count变量?这样,您可以确定输入参数是否错误(由C#移交)。

希望这有帮助

希望这有帮助


它在sql management studio中工作?使用
SELECT@Count
是多余的。您没有捕获
out
参数的值,因为您输入了
null
。它是使用存储过程旁边的FirstOrDefault()解决的。谢谢你们的帮助。它在sql management studio中工作吗?使用
SELECT@Count
是多余的。您没有捕获
out
参数的值,因为您输入了
null
。它是使用存储过程旁边的FirstOrDefault()解决的。谢谢你们的帮助。