Skip to content
This repository has been archived by the owner on Apr 5, 2019. It is now read-only.

Filters not taking effect when context caches entities? #22

Open
bjtaylor1 opened this issue Apr 23, 2015 · 2 comments
Open

Filters not taking effect when context caches entities? #22

bjtaylor1 opened this issue Apr 23, 2015 · 2 comments

Comments

@bjtaylor1
Copy link

Hi,
I tried to use this library for a filtering requirement my project has the other day.
It works great in terms of SQL - as long as a database query is actually run.
However, sometimes, the filter doesn't take effect and I think this is because EF has somehow 'cached' the entities - I know this because if I do a trace in SQL profiler, and refresh the page with changed parameters passed to the filter, then no new SQL query is run. The changed parameters have not taken effect.
However if I recycle the app pool, then refresh again with the changed paramters, then it does a new SQL query and the changed parameters take effect.
I was just wondering if there is any way round this?

Thanks

@AlbertoMonteiro
Copy link

You can use AsNoTracking method to always hit database ignoring cache

DbExtensions.AsNoTracking Method (IQueryable)
 Entity Framework 5.0+ 
Returns a new query where the entities returned will not be cached in the DbContext or ObjectContext. 

@bjtaylor1
Copy link
Author

OK, thanks - although this has to be applied at point of query, rather than once that will take effect across the board.
If I have to change (all the possibly very many instances of) the query code, I might as well just change them to put the filter in the query.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants