title: Entity Framework: Precompiled Query for Enumerable.Contains
body: <p>Entity Framework 5+ is supposed to precompile all queries. However, for queries such as</p>
  
  <pre><code>List&lt;Guid&gt; ids;
  var entities = context.MyEntities.Where(x =&gt; ids.Contains(x.Id)).ToArray();
  </code></pre>
  
  <p>Entity Framework cannot precompile the query, and depending on the complexity of the overall query, the parsing of the expression tree to SQL can consume several seconds. Has anyone found a workaround to get a precompiled query anyway? I do not really understand why it would be so hard; of course it is difficult to do with paramters, since the number of elements can differ, but it would be good enough to have SQL like</p>
  
  <pre><code>SELECT a, b, c from MyEntities
  WHERE c in __PLACEHOLDER__
  </code></pre>
  
  <p>and then to substitute the placeholder with the actual list elements. Of course, it is not as nice as passing parameters, but it would be by far better than waiting for seconds for parsing the entire expression tree over and over.</p>