title: When does a compiled query that returns an IQueryable execute?
body: <p>Okay I need a sanity check here...</p>
  
  <p>I've compiled a query that returns an IQueryable when executed.</p>
  
  <p><strong>On what line(s) should the query actually execute against the database in the following example?</strong></p>
  
  <pre><code>101 IQueryable&lt;T&gt; results = MyCompiledQuery(MyDataContext);
  102 List&lt;T&gt; final = (from t in result
  103                  where t.ID &gt; 5
  104                  select t).ToList&lt;T&gt;();
  </code></pre>
  
  <p>Here is how I define the compiled query</p>
  
  <pre><code> public static Func&lt;MyDataContext, IQueryable&lt;Widget&gt;&gt; MyCompiledQuery=
          CompiledQuery.Compile&lt;MyDataContext, IQueryable&lt;Widget&gt;&gt;(
                        (MyDataContext db) =&gt;
                        from w in db.Widgets
                        where ((w.Type == WidgetType.Atype ||  //Widget.Atype is a Linq to Sql object, that I've defined statically
                                w.Type == WidgetType.Btype ||  //See above comment
                                w.Type == WidgetType.Ctype ) &amp;&amp; //See above comment
                                w.Location == WidgetLocation.Domestic)  //Samething applies here
                          select euc);
  </code></pre>
  
  <p><strong>FOR ADDITIONAL DISCUSSION PLEASE REFER TO:</strong> 
  <a href="https://stackoverflow.com/questions/6592386/linq-to-sql-compiled-queries-and-when-they-execute/6597160#6597160">LINQ to SQL <em>compiled</em> queries and when they execute</a></p>