Entity Framework 6 - Uncached data with dependency injection

c# caching dependency-injection entity-framework-6

Accepted Answer

Long-lived contexts and entity tracking systems are known to have this problem.

The DbEntityEntry Several methods are provided by the class to update the cached entity data.Reload , GetDatabaseValues the object from the change tracker (hence the cache), and setting theState to Detached . However, they only apply to a single, known thing.

the previousObjectContext services offered a method to choose the query behaviour viaMergeOption number countingAppendOnly , OverwriteChanges , PreserveChanges and NoTracking However, they are all gone in aDbContext services, leaving zero tracking requests as the sole choice.

Consider employing the no tracking queries if you want to be certain that you'll retrieve the true database state by using.AsNoTracking() extension strategy. Remember that because the returned entities are essentially unconnected, changing them and then applying the changes back would be challenging and may result in exceptions like using the same key, an object has previously been tracked. etc.

2
8/26/2018 3:30:04 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow