为什么EF Core总是使用此存储过程返回-1?

时间:2017-04-28 20:21:32

标签: entity-framework .net-core entity-framework-core localdb

我正在尝试使用针对本地2016年数据库的EF Core(最新版本),我每次都会收到-1。我不知道我做错了什么?

我知道它正在到达数据库。我查了一下。

int returnCode = _dbContext.Database.ExecuteSqlCommand("CheckReceivedNotificationDuplicate @p0, @p1, @p2", 
parameters: new[] { sendMessage.MESSAGE_TEMPLATE_NAME, sendMessage.MESSAGE_SUBJECT, sendMessage.MESSAGE_TEXT_SUMMARY });

存储过程:

ALTER PROCEDURE [dbo].[CheckReceivedNotificationDuplicate]
@MESSAGE_TEMPLATE_NAME nvarchar(100),
@MESSAGE_SUBJECT nvarchar(255),
@MESSAGE_TEXT_SUMMARY nvarchar(4000)
AS  DECLARE @NMID Int
BEGIN   
IF  EXISTS (SELECT 1 FROM dbo.Notification WHERE MESSAGE_TEMPLATE_NAME = @MESSAGE_TEMPLATE_NAME
                and MESSAGE_SUBJECT = @MESSAGE_SUBJECT AND ReceiveTimeEST > dateadd(minute,-5, dbo.GetGMTtoEST(getutcdate())))
BEGIN 
    IF  EXISTS (SELECT 1 FROM dbo.Notification WHERE MESSAGE_TEMPLATE_NAME = @MESSAGE_TEMPLATE_NAME
                and MESSAGE_SUBJECT = @MESSAGE_SUBJECT AND MESSAGE_TEXT_SUMMARY = @MESSAGE_TEXT_SUMMARY
                AND ReceiveTimeEST > dateadd(minute,-5, dbo.GetGMTtoEST(getutcdate())))
        RETURN -99
    ELSE
        RETURN 0
END
ELSE
    RETURN 0
END

1 个答案:

答案 0 :(得分:4)

print("Digit", " ", "Count", " ", "%") for i in range(1,10): print(i, " ", num_count[i], " ", format(num_count[i]/total_num*100,".1f")) 在内部调用IRelationalCommand.ExecuteNonQuery。它返回受影响的行数。

要从存储过程返回任意值,请将输出参数添加到其声明和Digit Count % 1 5738 29.4 2 3540 18.1 3 2342 12.0 4 1847 9.5 5 1559 8.0 6 1370 7.0 7 1166 6.0 8 1043 5.3 9 904 4.6 调用:

ExecuteSqlCommand