Observers vs. Triggers

What is the general consensus?

If you need to change the database after a certain action, do you use the observer template and allow the framework / application to update for you? Or will you bypass the application and delegate the update to the database trigger?

The trigger is obviously faster, but is it worth it?

+3
source share
3 answers

I use triggers, but triggers usually depend on the database. If you plan to support multiple database servers, be sure to find a way to cover it in your code. If you are sure that you will use a specific database server, then you will like your data integrity for your triggers.

+3
source

LINQ2SQL, , SubmitChanges(). - . :

    /// <summary>
    /// Sends changes that were made to retrieved objects to the underlying database, 
    /// and specifies the action to be taken if the submission fails.
    /// NOTE: Handling this event to easily perform Audit tasks whenever a table gets updated.
    /// </summary>
    /// <param name="failureMode">The action to be taken if the submission fails. 
    /// Valid arguments are as follows:<see cref="F:System.Data.Linq.ConflictMode.FailOnFirstConflict"/>
    /// <see cref="F:System.Data.Linq.ConflictMode.ContinueOnConflict"/></param>
    public override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)
    {
        //Updates
        for (int changeCounter = 0; changeCounter < this.GetChangeSet().Updates.Count; changeCounter++)
        {
            object modifiedEntity = this.GetChangeSet().Updates[changeCounter];
            SetAuditStamp(this, modifiedEntity, ChangeType.Update);
        }

        //Inserts
        for (int changeCounter = 0; changeCounter < this.GetChangeSet().Inserts.Count; changeCounter++)
        {
            object modifiedEntity = this.GetChangeSet().Inserts[changeCounter];
            SetAuditStamp(this, modifiedEntity, ChangeType.Insert);
        }
        base.SubmitChanges(failureMode);

, , , ... , , , - , ...

+3

, 5 (), . , , . - . , , .

+2
source

All Articles