Search for existing suggestions

Hooks to intercept and modify queries on the fly at high and low level

We have seen that there are lots of discussion surrounding the generated SQL not being optimized. Entity Framework should have a provision wherein User should be able to change the Generated SQL and use it for further processing through some mechanism

50 votes
Sign in
Sign in with: facebook google
Signed in as (Sign out)

We’ll send you updates on this idea

JK (Jayakhanna P) shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →


Sign in
Sign in with: facebook google
Signed in as (Sign out)
  • Mohammad M commented  ·   ·  Flag as inappropriate

    I believe it would be much beneficial if it was possible to intercept queries like, select, where etc.
    The important thing for me would be that when intercepting, then the query result should be viewable.
    I need this to make security check regarding if the user querying the database also has access right the data he querying.
    This is unfortunately not possible now using interception e.g.:

    var listener = _context.GetService<DiagnosticSource>();
    (listener as DiagnosticListener).SubscribeWithAdapter(new CommandListener());

    using commercial tools like postSharp to do this is not the way I want to go.

  • Arturo Hernandez commented  ·   ·  Flag as inappropriate

    This is similar to the idea of modifying a generated SQL. Except that it applies to an earlier stage. I can imagine a scenario where a third party may come up with a really good LINQ optimizer.

  • dwbanks commented  ·   ·  Flag as inappropriate

    Add hooks thourought the process from QueryExecuting to QueryExecuted - great place to add auditing/security code

  • Paul King commented  ·   ·  Flag as inappropriate

    To expand on this a bit further, this would allow us to do something with an Entity before it is added to the ObjectStateManager, including reject the Entity entirely.

    This “QueryStarting” event would allow us to “rewrite” the query by wrapping it in an outer query that adds a filter to the results from the main query.

    Doing this at the event level allows this type of filtering to be placed in one place int he code instead of on each query being executed.

Feedback and Knowledge Base