Background:
I have a website (ASP.NET MVC) where users can write/edit/delete a “review”.
Doing so needs to kick off a database trigger to update some global statistics on the system.
Database Tables:
- Review (parent)
- MetaData1 (Review 1 – 0..1 MetaData1)
- MetaData2 (Review 1 – 0..1 MetaData2)
- MetaData3 (Review 1 – 0..* MetaData3)
So Review is the main table (ReviewId – identity), and the other’s are meta data.
The problem:
I have a stored procedure which performs the calculations, which needs to be called whenever a review is created/edited/deleted.
At the moment, i have a trigger which calls the SP on all tables (4 identical triggers). But this results in the stored procedure being executed possibly 4 times when it only needs to be done once.
I can’t just put it on Review only, because if a user edits metadata for a review, Review table will not be touched and hence the trigger will not fire.
I need a way of saying “watch all of these tables for activity, when a record is created/edited/deleted, fire off this procedure once.”
Any tips/suggestions/ideas?
FYI – i’m using Entity Framework 4 for the CRUD operations, if that matters.
Drop triggers on 3 MetaDataX tables. After saving metadata records, really change something (“last edited” time would be a good candidate) in the Review table.
You may want to write some proxy methods to implement the above logic in Review mapped class to manipulate the metadata objects (and do not use MetaDataX mapped objects directly).