0

Why is IDbCommandTreeInterceptor being skipped on second query?

Answered here, query command trees are cached by model which means that command tree creation only happens the first time a query is executed. So how would I force EF to create new query commands, or if that is not possible how would I go about implementing an interceptor to achieve row level restrictions on the application level.

John Staurt
  • 225
  • 3
  • 13
  • Could you use a `DbCommandInterceptor` and override `NonQueryExecuting` to do the work you wanted to do there? – Scott Chamberlain Oct 11 '17 at 14:54
  • What's a "row level restriction" in this case? Permission for a user to see or not see a whole row based on access checks, or something more complicated involving columns? [See also](https://stackoverflow.com/q/30173913/4137916). Frankly, this would motivate me to consider moving the restriction to the database itself ([which is viable from SQL Server 2016 onwards](https://learn.microsoft.com/sql/relational-databases/security/row-level-security)). Although, realistically, I wouldn't be using EF in the first place so there's little trouble adding it to my DB layer. – Jeroen Mostert Oct 11 '17 at 14:56
  • @ScottChamberlain can you put that as an answer so I can mark as correct – John Staurt Oct 14 '17 at 06:33

1 Answers1

1

Instead of using a IDbCommandTreeInterceptor use a class derived from DbCommandInterceptor and override NonQueryExecuting to do the work you wanted to do there.

Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431