Laraue.EfCoreTriggers package for creating SQL triggers through fluent syntax which allows to execute insert, update, upsert, delete, insert if not exists statements after trigger has worked like this
modelBuilder.Entity<Transaction>()
.AfterInsert(trigger => trigger
.Action(triggerAction => triggerAction
.Upsert(transaction => new { transaction.UserId },
insertedTransaction => new UserBalance { UserId = transaction.UserId, Balance = insertedTransaction.Sum },
(insertedTransaction, oldBalance) => new UserBalance { Balance = oldBalance.Balance + insertedTransaction.Sum })));
This code will be translated into sql and applied to migrations using
migrationBuilder.Sql()
mysql
,postgresql
,sql-server
,oracle
ordb2
- or something else entirely. – VollmermigrationBuilder.Sql("CREATE TRIGGER …")
etc. – Jenisejenkel