It seems that if I try to update a table on a delete trigger, but in the finding of the rows to update I compare a property to a constant char, incorrect SQL is generated. If I have tables like below
public class Project {
[Key]
public int ID { get; set; }
}
public class ProjectHistory {
[Key]
public int ID { get; set; }
public int ProjectID { get; set; }
public char ChangeType { get; set; }
}
and this time, instead of inserting a new ProjectHistory row, I want to find a suitable history row to update with a trigger like this:
then everything else goes fine, but the comparison of the ChangeType is incorrect:
ALTER TRIGGER [dbo].[LC_TRIGGER_AFTER_DELETE_PROJECT] ON [dbo].[Project] AFTER Delete AS
BEGIN
DECLARE @OldID INT
DECLARE DeletedProjectCursor CURSOR FOR SELECT ID FROM Deleted
OPEN DeletedProjectCursor
FETCH NEXT FROM DeletedProjectCursor INTO @OldID
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE ProjectHistory
SET ChangeType = 'D'
WHERE CAST(ProjectHistory.ChangeType AS INT) = 85 AND ProjectHistory.ProjectID = @OldID;
FETCH NEXT FROM DeletedProjectCursor INTO @OldID
END
CLOSE DeletedProjectCursor DEALLOCATE DeletedProjectCursor
END
and deletion from Project fails with
"Msg 245, Level 16, State 1, Procedure LC_TRIGGER_AFTER_DELETE_PROJECT, Line 9 [Batch Start Line 25]
Conversion failed when converting the nvarchar value 'U' to data type int."
Unfortunately, I am not currently able to develop for .NET6 so this is coming from library version 5.3.3.
It seems that if I try to update a table on a delete trigger, but in the finding of the rows to update I compare a property to a constant char, incorrect SQL is generated. If I have tables like below
and this time, instead of inserting a new ProjectHistory row, I want to find a suitable history row to update with a trigger like this:
then everything else goes fine, but the comparison of the ChangeType is incorrect:
and deletion from Project fails with
"Msg 245, Level 16, State 1, Procedure LC_TRIGGER_AFTER_DELETE_PROJECT, Line 9 [Batch Start Line 25] Conversion failed when converting the nvarchar value 'U' to data type int."
Unfortunately, I am not currently able to develop for .NET6 so this is coming from library version 5.3.3.