Description
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)
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
'sRolledBack
andCommitted
hooks.If the new
AfterSaveChanges
event of EFCore supported the following this logic described above could be simplified:EFCache
could 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.
SidShetye commentedon Jul 23, 2019
@ajcvickers Could we please have this for 3.1 (along with it's counterpart in #15911)
41 remaining items
Add SaveChanges events (#21862)