title: When should I use a CompiledQuery?
body: <p>I have a table:</p>
  
  <pre><code>-- Tag
  
  ID  | Name
  -----------
  1   | c#
  2   | linq
  3   | entity-framework
  </code></pre>
  
  <p>I have a class that will have the following methods:</p>
  
  <pre><code>IEnumerable&lt;Tag&gt; GetAll();
  IEnumerable&lt;Tag&gt; GetByName();
  </code></pre>
  
  <p>Should I use a compiled query in this case?</p>
  
  <pre><code>static readonly Func&lt;Entities, IEnumerable&lt;Tag&gt;&gt; AllTags =
      CompiledQuery.Compile&lt;Entities, IEnumerable&lt;Tag&gt;&gt;
      (
          e =&gt; e.Tags
      );
  </code></pre>
  
  <p>Then my <code>GetByName</code> method would be:</p>
  
  <pre><code>IEnumerable&lt;Tag&gt; GetByName(string name)
  {
      using (var db = new Entities())
      {
          return AllTags(db).Where(t =&gt; t.Name.Contains(name)).ToList();
      }
  }
  </code></pre>
  
  <p>Which generates a <code>SELECT ID, Name FROM Tag</code> and execute <code>Where</code> on the code. Or should I avoid <code>CompiledQuery</code> in this case?</p>
  
  <p>Basically I want to know when I should use compiled queries. Also, on a website they are compiled only once for the entire application?</p>