Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a trigger for updating a specific column #95

Open
Vasypu opened this issue Dec 27, 2023 · 2 comments
Open

add a trigger for updating a specific column #95

Vasypu opened this issue Dec 27, 2023 · 2 comments

Comments

@Vasypu
Copy link

Vasypu commented Dec 27, 2023

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")));
@win7user10
Copy link
Owner

You can try something like

modelBuilder.Entity<YourEntity>()
            .AfterUpdate(trigger => trigger
                .Condition(refs => refs.Old.Column1 != refs.New.Column1)
                .ExecuteRawSql("some sql"));

@Vasypu
Copy link
Author

Vasypu commented Dec 29, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants