Warning: file_put_contents(/datas/wwwroot/jiajiahui/core/caches/caches_template/2/default/show.php): failed to open stream: Permission denied in /datas/wwwroot/jiajiahui/core/libraries/classes/template_cache.class.php on line 55

Warning: chmod(): Operation not permitted in /datas/wwwroot/jiajiahui/core/libraries/classes/template_cache.class.php on line 56
在EF C#中显示空值的SQL Server输出参数# - 源码之家

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

问题描述:

我有一个带输出参数的下面的存储过程。在EF C#中显示空值的SQL Server输出参数#

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 [email protected] and fdIsConsumerType=1 and fdIsReadatAdmin=0) 
    else 
    select @Count=(Select count(fdId) from tb_CRS_Messages where [email protected] and fdIsMemberType=1 and fdIsReadatAdmin=0) 
    end 
else 
begin 
    if @type='consumer' 
    select @Count=(Select count(fdId) from tb_CRS_Messages where [email protected] and fdIsConsumerType=1 and fdIsReadatFront=0) 
else 
select @Count=(Select count(fdId) from tb_CRS_Messages where [email protected] and fdIsMemberType=1 and fdIsReadatFront=0) 
END 
SELECT @Count 
END 

这是在SQL服务器完美的工作见下面的输出:

我打电话这个stored procedure通过Entity Framework

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值。

请帮忙。

+0

,它在SQL Management Studio中的作品? – jamiedanq

+0

使用'SELECT @ Count'是多余的。您不输入'out'参数的值,因为您输入'null'。 –

+0

它使用存储过程旁边的FirstOrDefault()来解决。 谢谢你们的帮助。 –

不知道它是否有所作为,但您是否尝试使用“typeof(Int32)”而不是“typeof(int)”?也可以尝试NewMessage作为ObjectParameter,而不是var,也许它有所作为。

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

您是否尝试运行没有参数的存储过程,意味着无论您输入什么参数都返回@ Count-variable值?像这样,您可以识别您的输入参数是否错误(由C#移交)或不。