Laraue.EfCoreTriggers
Laraue.EfCoreTriggers copied to clipboard
add a trigger for updating a specific column
Is it possible to add to the library support for triggers that are triggered only when certain columns in the table are updated?
expected sql of such a trigger:
CREATE TRIGGER trg_update_trigger
AFTER UPDATE OF column1 ON your_table
FOR EACH ROW
EXECUTE FUNCTION your_update_function();
syntax how it would look like:
modelBuilder.Entity<YourEntity>()
.AfterUpdateOf(x => x.column1
.Action(x => x.ExecuteRawSql("some sql")));
You can try something like
modelBuilder.Entity<YourEntity>()
.AfterUpdate(trigger => trigger
.Condition(refs => refs.Old.Column1 != refs.New.Column1)
.ExecuteRawSql("some sql"));
that's what I did, but this code generates the following sql
CREATE FUNCTION myFunction() RETURNS trigger as $LC_TRIGGER_AFTER_UPDATE_MYFUNCTION$
BEGIN
IF NEW."Column1" <> OLD."Column1" OR NEW."Column2" <> OLD."Column2" THEN
....
END IF;
RETURN NEW;
END;
$LC_TRIGGER_AFTER_UPDATE_MYFUNCTION$ LANGUAGE plpgsql;
CREATE TRIGGER LC_TRIGGER_AFTER_UPDATE_MYFUNCTION AFTER UPDATE
ON your_table
FOR EACH ROW EXECUTE PROCEDURE myFunction();
and I need the trigger condition to be triggered not in the trigger body, as it is here.
CREATE TRIGGER trg_update_trigger
AFTER UPDATE OF column1 ON your_table
FOR EACH ROW
EXECUTE FUNCTION your_update_function();
is there any possibility with the next update to add support for triggers on certain table columns?