1

Using entity framework I have implemented soft delete & data level restriction with IDbCommandTreeInterceptor. For the first query using the context, the interceptor gets hit. But trying again (refreshing browser), the interceptor is skipped. I have checked whether data is being cached by changing some data using SQL server management studio. The changes are reflected but the interceptor is still skipped. What could possibly be causing for this to happen?

John Staurt
  • 225
  • 3
  • 13

1 Answers1

2

according to the sources comments this is expected behaviour

Command trees are created for both queries and insert/update/delete commands. However, query command trees are cached by model which means that command tree creation only happens the first time a query is executed and this notification will only happen at that time

As a consequence your interceptor result can not depend on the data.

jbl
  • 15,179
  • 3
  • 34
  • 101
  • Understandable, but one bit that still is confusing is that the interceptor gets hit (for the old query) if I run a new query, then rerun the old query through EF. But then if both queries has already been executed once, the interceptor is skipped again for both interchangeably, until a new query is executed. Then Interceptor gets hit for the new query and both the old queries. – John Staurt Oct 09 '17 at 16:27
  • @JohnStaurt unexpected indeed. Have you modified the queryCache section of the configuration (see https://blogs.msdn.microsoft.com/premier_developer/2017/03/23/entity-framework-query-caching/ ) ? – jbl Oct 09 '17 at 16:45