Ability to ignore triggers on a query #113
Replies: 3 comments 3 replies
-
This is an interesting idea. What you're asking for is a way of 'marking' entities to not raise triggers for, so given the following example: var jon = dbContext.Users.WithNoTriggers().FirstOrDefault(x => x.Name == "Jon");
var jane = dbContext.Users.FirstOrDefault(x => x.Name == "Jane");
jon.Counter += 1;
jane.Counter += 1;
dbContext.SaveChanges(); This will only raise triggers for Jane as Jon has been tracked with a hypothetical WithNoTriggers behavior. This will still require a design in order to mark new and attached entities to not raise triggers. I've thought about something similar (yet different), namely the ability to disable triggers on demand. Something like the following: dbContext.GetTriggerService().DisableTriggers();
dbContext.SaveChanges(); // This will NOT raise any triggers
dbContext.GetTriggerService().EnableTriggers();
// Or in short an extension method: dbContext.SaveChangesWithNoTriggers(); This does in turn not allow the fine grained control to only enable Triggers for specific entities but It would simplify a whole lot. Would my alternative approach work in your case? |
Beta Was this translation helpful? Give feedback.
-
This is tracked in #114 |
Beta Was this translation helpful? Give feedback.
-
Support for this is now in the master branch and will soon be released (under preview). The following can be used to save changes without invoking triggers: using EntityFrameworkCore.Triggered.Extensions;
dbContext.SaveChangesWithoutTriggers(); |
Beta Was this translation helpful? Give feedback.
-
Issue
I have a part of my system that is constantly hitting the API and calling an update on a table, I do not want this specific call to pass through the trigger pipeline.
The current work around
This performance hit can be avoided by using a different ORM for the query or by running the query as raw sql
Goal
It would be nice to have an extension method to add to a ef query that would be similar to ef cores AsNoTracking() maybe WithNoTriggers() that would allow the user to make sure that triggers would not be called during the pipeline to improve performance for queries
Beta Was this translation helpful? Give feedback.
All reactions