-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
I feel like I'm a bit dense here.
I haven't been able to get something like https://www.npgsql.org/efcore/modeling/generated-properties.html#timestamp-generation working:
CREATE FUNCTION "Blogs_Update_Timestamp_Function"() RETURNS TRIGGER LANGUAGE PLPGSQL AS $$
BEGIN
NEW.timestamp := CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$;
CREATE TRIGGER "UpdateTimestamp"
BEFORE INSERT OR UPDATE
ON "Blogs"
FOR EACH ROW
EXECUTE FUNCTION "Blogs_Update_Timestamp_Function"();I end up having to do something like:
entity.BeforeInsert(trigger =>
trigger.Action(action => action.ExecuteRawSql("NEW.timestamp = CURRENT_TIMESTAMP"))
);
entity.BeforeUpdate(trigger =>
trigger.Action(action => action.ExecuteRawSql("NEW.timestamp = CURRENT_TIMESTAMP"))
);Ideally, I'd do something like:
// Note BeforeInsertOrUpdate, which doesn't currently exist
entity.BeforeInsertOrUpdate(trigger =>
trigger.Action(action =>
// Some NON "ExecuteRawSql" action here against my entity type
)
);But I can't figure out:
- How to do this without
ExecuteRawSql - How to do something like a combined
BeforeInsertOrUpdate(less of a concern as we can have a default value on the column)
Thanks for any insights.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels