win7user10 / Laraue.EfCoreTriggers

Library to write triggers in C# with EF.Core
MIT License
111 stars 20 forks source link

Null comparison creates wrong SQL #57

Closed JarRami closed 1 year ago

JarRami commented 1 year ago

If I have a table like

public class NullableHolder {
    [Key]
    public int ID { get; set; }
    public int? Value { get; set; }
}

And I create Insert and Update triggers like (take note of the comparisons)

modelBuilder.Entity<NullableHolder>()
    .AfterInsert(trigger => trigger
        .Action(action => action
            .Condition(nh => nh.Value != null)
        )
    )
    .AfterUpdate(trigger => trigger
        .Action(action => action
            .Condition((before, after) => (before.Value != null) && (after.Value == null))
        )
    );

After running Add-Migration I get the following triggers

CREATE TRIGGER LC_TRIGGER_AFTER_INSERT_NULLABLEHOLDER 
--
IF (@NewValue IS NULL)

and

CREATE TRIGGER LC_TRIGGER_AFTER_UPDATE_NULLABLEHOLDER 
--
IF (@OldValue IS NULL AND @NewValue IS NULL)

Two of the created IS NULLs seem to be incorrect when it's created even when the actual comparison was .Value != null?

Unfortunately, I'm not able to run .NET6 so this behaviour is seen against library version 5.3.6.

win7user10 commented 1 year ago

Fixed in https://github.com/win7user10/Laraue.EfCoreTriggers/issues/71

JarRami commented 1 year ago

This seems to work, thankyou