title: Can someone explain why this LINQ-to-entitiy query causes an error, and why my solution fixes it?
body: <p>The expression that is thrown is:</p>
  <blockquote>
  <p>System.NotSupportedException: 'Unable to create a constant value of
  type 'CantShowYouThis'. Only primitive types or enumeration types are
  supported in this context.'</p>
  </blockquote>
  <p>Query that causes an error</p>
  <pre><code>context.tableA.RemoveRange(context.tableA.Where(conflict =&gt; listOfCantShowYouThis.Select(r =&gt; 
  r.Id).Contains(conflict.RequestId)));
  </code></pre>
  <p>Solution:</p>
  <pre><code>var list = listOfCantShowYouThis.Select(r =&gt; r.Id);
  context.tableA.RemoveRange(context.tableA.Where(conflict =&gt; list.Contains(conflict.RequestId)));
  </code></pre>
  <p>This code is taken from the codebase I'm working with, so I've had to remove the names of classes and such just to stay on the safe side.</p>
  <p>From googling a bit I think it is related to the mixing of in-memory data and database data which EF / LINQ-to-entity doesn't like. I might be wrong, but even if I'm not, it is still a very shallow understanding of what is going on. I'd like to understand why my fix works. I know that doing Select won't really do much until it is actually used (by calling ToList() or some other method), because of deferred execution so it strange to me that moving it like this solves the problem.</p>