title: LINQ to SQL DataContext Caching
body: <p>I am using Linq to SQL as my DAL layer and during unit test I found out that my objects are not being returned from database but from the DataContext cache. </p>
  
  <p>The strange thing is that when the objects are returned from the cache why does it require a separate call to the database to fetch all the fields. </p>
  
  <p>Anyway, I implemented a ClearCache method that will clear out the cache. But I am only clearing the cache in the unit test and not in the API code. </p>
  
  <p>The reason is that once the object is inserted it is good to load from the cache then to fetch it again from the database. </p>
  
  <p>What do you think? </p>
  
  <p><strong>UPDATE</strong>: </p>
  
  <pre><code>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);
          }
  </code></pre>