Clear cached entities

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
Posts: 7
Joined: Wed 09 Nov 2011 13:01

Clear cached entities

Post by soren » Mon 14 Nov 2011 13:39

In Linq2Sql you can, through reflection, call a ClearCache on the DataContext to have it throw the internally "cahced" entities which is a great help for us in integration testing to ensure data is read from the database and not the cached identity map.

Do you have something that resembles this? I can see you obfuscate your assemblies so reflection is pretty much out of the picture but could this be achieved somehow?

Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Wed 16 Nov 2011 18:08

To ensure you are working with the data actually available in the database and not the ones cached in the context, you can use the Refresh method of DataContext with the OverwriteCurrentValues refresh mode.

More generally, the recommended approach for working with the LinqConnect DataContext type (and the one of LINQ to SQL as well) is to use a new DataContext instance for each unit of work. This should significantly reduce the probability of working with stale data, as entity caches work on the DataContext instance level (i.e., cached entities are not shared between DataContexts).

Please tell us if this helps.

Post Reply