问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/46650065/why-is-idbcommandtreeinterceptor-being-skipped-on-second-query