title: Is it OK to open a DB4o file for query, insert, update multiple times?
body: <p>This is the way I am thinking of using DB4o.  When I need to query, I would open the file, read and close:</p>
  
  <pre><code>using (IObjectContainer db = Db4oFactory.OpenFile(Db4oFactory.NewConfiguration(), YapFileName))
  {
      try
      {
          List&lt;Pilot&gt; pilots = db.Query&lt;Pilot&gt;().ToList&lt;Pilot&gt;();
      }
      finally
      {
         try { db.Close(); }
         catch (Exception) { };
      }
  }
  </code></pre>
  
  <p>At some later time, when I need to insert, then</p>
  
  <pre><code>using (IObjectContainer db = Db4oFactory.OpenFile(Db4oFactory.NewConfiguration(), YapFileName))
  {
      try
      {
          Pilot pilot1 = new Pilot("Michael Schumacher", 100);
          db.Store(pilot1);
      }
      finally
      {
         try { db.Close(); }
         catch (Exception) { };
      }
  }
  </code></pre>
  
  <p>In this way, I thought I will keep the file more tidy by only having it open when needed, and have it closed most of the time.  But I keep getting InvalidCastException</p>
  
  <pre><code>Unable to cast object of type 'Db4objects.Db4o.Reflect.Generic.GenericObject' to type 'Pilot'
  </code></pre>
  
  <p>What's the correct way to use DB4o?</p>