-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement event for before DBCommand is executed #15988
Comments
Note for triage: related to #15066 and other interceptors. |
Scenarios are partially covered by #15066. Moving to the backlog for the rest. |
Note that #17261 is basically a duplicate of this, although they come from different directions. |
Closing this since command interceptors are the hook to use before any command is executed; this is already implemented for 3.0. #17261 tracks possible changes to the command creation event to move it closer to when it is used, but this isn't necessary for the behavior requested here. |
As requested in the Lifecycle hooks Epic (#626), this is one of the hooks/events we need for our use cases.
The event would execute before any DBCommand is executed.
Our use case is implementing a query level cache based on EFCache. To implement this cache, we need to capture a query before it's executed, so we can look it up and use the cached result.
For this we'd need an event that's executed before a DBCommand is executed. It should preferably expose the entity sets affected by the DBCommand and expose the SQL Query that's about to be executed (or a unique identifier that's always the same for the same query). It should also be able to stop the DBCommand from being executed on the database, so the cached result can be returned instead.
EFCache accomplishes this in EF6 by implementing a custom DBProviderServices object which captures the original DBCommandDefinition in a CachingCommandDefinition. This
CachingCommandDefinition
creates a CachingCommand which returns the cached result onExecuteDbDataReader
, or, if no cached result exists, it executes the originalDbCommand
.If the event I described would be exposed, it would make this process a lot easier. Creating a custom
QueryProvider
should not be necessary.See also this comment by the author of EFCache: #5858 (comment)
The text was updated successfully, but these errors were encountered: