title: What are the best practices for determining when (or not) to pre-compile a Linq Query?
body: <p>I am currently refactoring a silverlight application and pulling out frequently used queries to a utility class.  There are a lot of queries in the application, and while there were some obvious targets, when I get down to very small queries like this:</p>
  
  <pre><code>public static readonly Func&lt;STARSEntities, int&gt; CurrentFundingYearId =
          CompiledQuery.Compile&lt;STARSEntities, int&gt;(
          (ctx) =&gt;
              (ctx.STARS_FundingYear.Where(i =&gt; i.IsCurrentYear == true)).FirstOrDefault().FundingYearId);
  </code></pre>
  
  <p>Is it worth compiling?  Everything I've read (<a href="http://oreilly.com/catalog/9780596807269" rel="nofollow">Programming Entity Framework 2ed</a>) and various online sources say that there are performance boosts, but I haven't found anything that outlines when NOT to pre-compile (besides the fact that you can't return anonymous types, so no projection).</p>
  
  <p>Edit: Good background article about compiled queries: <a href="http://msdn.microsoft.com/en-us/magazine/ee336024.aspx" rel="nofollow">Precompiling LINQ Queries</a></p>
  
  <p>What are the best practices for determining when (or not) to pre-compile a Linq Query in an application?</p>