title: Force immediate execution of IEnumerable query using Linq2Sql context
body: <p>I've read a considerable amount of posts regarding the "possible multiple enumeration" issue. I think I understand the concepts of deferred vs. immediate execution, as well as the implications of returning interfaces vs. concrete types.</p>
  
  <p>So given the data access layer method below and the test code, I am trying to force immediate execution of the query. <code>ToList()</code> works in the data access layer method, but not in the Main method (probably because <code>ToList()</code> is called after the context is disposed). Casting <code>as ReadOnlyCollection&lt;Item&gt;</code> (or <code>IReadOnlyCollection</code>) also do not work.</p>
  
  <pre><code>    static void Main(string[] args)
      {
          var foo = GetItems(i =&gt; i.SupiCode.Contains("TestCode")).ToList(); // ObjectDisposedException (context)
      }
  
      private static IEnumerable&lt;Item&gt; GetItems(Func&lt;Item, bool&gt; filter)
      {
          using (var ctx = new RRPClassesDataContext())
          {
              return ctx.Item.Where(filter); //.ToList(); &lt;-- this works
          }
      }
  </code></pre>
  
  <p>My objectives are to prevent multiple enumeration (i.e. multiple database access). From what I read, I should not modify the DAL to fit customer need. Instead, customer should handle the returned <code>IEnumerable</code> properly. So my questions are:</p>
  
  <ul>
  <li>in this situation, can the customer force the immediate execution (if yes, how)?</li>
  <li>should the DAL return <code>.ToList()</code> and/or the signature be modified?</li>
  </ul>