You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implement events for before and after SaveChanges #15910
Splitting this out as a separate issue as required on #626 so we can track it independently of other life-cycle hooks.
SavingChanges: An event fired when the entity object is just about to be written to the database.
SavedChanges: An event fired after the SavingChanges operation has completed (successfully or otherwise)
Reacted by Sid Shaytay, Shimmy Weitzhandler, Nick Muller, Martyn, Yann Zahringer Ferrando, Douglas Gaskell, Igor, Кирилл Шмойлов, Olivier Kaluzny, Duranom and 12 more
For my main use case: A query level cache, it looks like I'd need an event after SaveChanges.
Specifically, I need to know if the transaction has been committed (succeeded) or has been rolled back.
Basically EFCache is using a custom DBCommand to figure out which entity sets are affected during Save/Rollback. It only needs to invalidate every cache entry of the specific entity set, so that's all the information it needs. The invalidation is done via IDbTransactionInterceptor's RolledBack and Committed hooks.
If the new AfterSaveChanges event of EFCore supported the following this logic described above could be simplified:
The event needs to expose if the transaction got committed or if it got rolled back.
If it could expose which entity sets are affected by the transaction, much of the logic of EFCache could be simplified.
See also this comment by the author of EFCache: #5858 (comment)
@nphmuller Thanks for the info. I've also been doing some experiments with database interceptors, similar to EF6, which might be a better fit for this.
Activity
nphmuller commentedon Jun 7, 2019
For my main use case: A query level cache, it looks like I'd need an event after SaveChanges.
Specifically, I need to know if the transaction has been committed (succeeded) or has been rolled back.
The query level cache we used for EF6 was based on this project: https://github.com/moozzyk/EFCache
We're basically thinking of porting this to EFCore if the necessary events are supported. Of course things maybe can be simplified.
Basically EFCache is using a custom DBCommand to figure out which entity sets are affected during Save/Rollback. It only needs to invalidate every cache entry of the specific entity set, so that's all the information it needs. The invalidation is done via
IDbTransactionInterceptor'sRolledBackandCommittedhooks.If the new
AfterSaveChangesevent of EFCore supported the following this logic described above could be simplified:EFCachecould be simplified.See also this comment by the author of EFCache: #5858 (comment)
ajcvickers commentedon Jun 7, 2019
@nphmuller Thanks for the info. I've also been doing some experiments with database interceptors, similar to EF6, which might be a better fit for this.
douglasg14b commentedon Jun 16, 2019
My use case for this would be logging and audit trails.
SidShaytay commentedon Jul 23, 2019
@ajcvickers Could we please have this for 3.1 (along with it's counterpart in #15911)
ajcvickers commentedon Jul 25, 2019
@SidShetye We haven't decided what will be in 3.1 yet.
30 remaining items
Add SaveChanges interceptor (#21857)
Add SaveChanges events
Add SaveChanges events
Add SaveChanges events (#21862)