Data Base Triggers

Feb 28, 2015 at 4:49 PM
I have a application that i am planning to move to VITA but it uses database triggers to mantain totals on summary rows, is there any way to execute custom SQL when the tables are created by VITA?

Regards,
Coordinator
Feb 28, 2015 at 5:49 PM
There's no support for triggers - they're too db-server specific, and quite controversial in their benefits/troubles scale. I personally have distaste for them, and never used them. Not to bash your decisions, but to explain why it's not there, and likely will not appear in the near future.
The alternative (much better I think) is to use event system in VITA - they are c# equivalent of triggers. The runtime fires events at entity-type level whenever entity is saved or saving it is fired.
For example, if you want to hook to IBookOrderLine save and update Order.Total you can do something like this:

in BooksModule.Init:
  var entInfo = App.Model.GetEntityInfo(typeof(IBookOrderLine));
  entInfo.SaveEvents.SavingChanges += BookSaveEvents_SavingChanges;
In SavingChanges handler, get Order entity for OrderLine and recalc total. There's one problem - this event handler will be fired several times in one transaction, if you update several lines. I need to see more inside VITA if you can avoid it - I'll get back to you on this.

If you want to keep triggers, then you can put them in separate script and run manually (once, after VITA initially updates changes to the model). Then VITA will be keeping up tables/stored procs, without touching triggers. I will definitely introduce facility for running custom scripts on model update (in fact it was there at some time but was lost in refactorings).
Feb 28, 2015 at 5:55 PM
Thanks for the fast reply.