I use Linq for SQL as my DAL level, and during unit test I found that my objects are not returned from the database, but from the DataContext cache.
The strange thing is that when objects are returned from the cache, which requires a separate database call to retrieve all the fields.
In any case, I applied the ClearCache method, which will clear the cache. But I clear the cache in unit test, not in the API code.
The reason is that after an object is inserted, it is useful to load from the cache and then retrieve it from the database again.
What do you think?
UPDATE :
public static void ClearCache(this EStudyModelDataContext context)
{
const BindingFlags Flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
var method = context.GetType().GetMethod("ClearCache", Flags);
method.Invoke(context, null);
}
source
share