Skip to content
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

Closed
nphmuller opened this issue Jun 7, 2019 · 4 comments
Closed

Implement event for before DBCommand is executed #15988

nphmuller opened this issue Jun 7, 2019 · 4 comments

Comments

@nphmuller
Copy link

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 on ExecuteDbDataReader, or, if no cached result exists, it executes the original DbCommand.

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)

@nphmuller nphmuller changed the title Implement event before DBCommand is executed Implement event for before DBCommand is executed Jun 7, 2019
@ajcvickers
Copy link
Member

Note for triage: related to #15066 and other interceptors.

@ajcvickers
Copy link
Member

Scenarios are partially covered by #15066. Moving to the backlog for the rest.

@ajcvickers
Copy link
Member

Note that #17261 is basically a duplicate of this, although they come from different directions.

@ajcvickers
Copy link
Member

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.

@ajcvickers ajcvickers removed this from the Backlog milestone Sep 7, 2019
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants