We're having a problem testing Entity Framework 4.
We've deployed a WCF service that implements an EF data context. All works fine untill we modify the data using SQL server studio.
Is there a way to stop EF caching our results or is there any way to turn eager loading on?
Cheers,
James
Entity Framework has the following forms of caching built-in: Object caching – the ObjectStateManager built into an ObjectContext instance keeps track in memory of the objects that have been retrieved using that instance. This is also known as first-level cache.
The Cache: The memory cache is used by default.
The first time a query is invoked, data is retrieved from the database and stored in memory before being returned. The compiled queries could be cached for the life of an app pool instance and provided to the Entity Framework for low latency performance of data access.
AsNoTracking(IQueryable)Returns a new query where the entities returned will not be cached in the DbContext or ObjectContext. This method works by calling the AsNoTracking method of the underlying query object.
On the property sheet for your model, you can set the Lazy Loading Enabled
property.
Through code, you can control lazy loading with the ObjectContextOptions.LazyLoadingEnabled
property:
context.ContextOptions.LazyLoadingEnabled = false;
In EF4 I had to use this instead:
_context.Configuration.LazyLoadingEnabled = false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With