How to bypass cache in a single Entity Framework 4.0 request?

Is there a way in Entity Framework 4.0 to bypass object cache for a single LINQ query?

I want to be able to execute the request and know that I am getting the absolute value from the database, even if this object was previously received in the request and was stored in the cache.

+4
source share
1 answer

You must configure your query or object to force the materialization of the result set instead of using already materialized objects from the identification map.

context.YourObjectSet.MergeOption = MergeOption.OverwriteChanges; // now execute the query as many times as you want 

or

 var query = ...; ((ObjectQuery<YourEntity>)query).MergeOption = MergeOption.OverwriteChanges; 
+3
source

Source: https://habr.com/ru/post/1398654/


All Articles