EntityFrameworkCore 5.05 ExecuteSqlRaw fail multiple update
James Bound
1
Reputation point
I try to Execute a stored procedure from , if I execute it directly from SSMS, it works as expected, but if I use it from ExecuteSqlRaw or ExecuteSqlRawAsync, it fails as soon as it hits the first SELECT COUNT(), no error, but the second UPDATE never run.
An example of the stored procedure:
ALTER PROCEDURE [fact].[SetJobDoneByProcess]
@JobId int
,@JobProcId int
,@JobUserId smallint
,@Done bit
AS
BEGIN
DECLARE @procCnt int = 0
,@procCntDone int = 0
,@CompletedDtTm datetime = NULL;
--Update this process status
IF @Done = 1
BEGIN
SET @CompletedDtTm = GETDATE();
END
UPDATE fact.Jobs_Processes
SET CompletedDtTm = @CompletedDtTm, JobUserId = @JobUserId
WHERE JobProcId = @JobProcId
-- Compare job processes finished
SET @CompletedDtTm = NULL;
SET @procCnt = (SELECT COUNT(JobProcId) FROM fact.Jobs_Processes WHERE JobId = @JobId)
SET @procCntDone = (SELECT COUNT(JobProcId) FROM fact.Jobs_Processes WHERE JobId = @JobId AND NOT CompletedDtTm IS NULL)
-- Update job
IF @procCnt = @procCntDone
BEGIN
SET @CompletedDtTm = GETDATE();
UPDATE fact.Jobs
SET CompletedDtTm = @CompletedDtTm
WHERE JobId = @JobId
END
ELSE
BEGIN
UPDATE fact.Jobs
SET StartedDtTm = GETDATE()
WHERE JobId = @JobId
AND StartedDtTm IS NULL
END
END
Sign in to answer