我有一個帶輸出參數的下面的存儲過程。在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
值。
請幫忙。
,它在SQL Management Studio中的作品? – jamiedanq
使用'SELECT @ Count'是多餘的。您不輸入'out'參數的值,因爲您輸入'null'。 –
它使用存儲過程旁邊的FirstOrDefault()來解決。 謝謝你們的幫助。 –