title: Entity Framework: Can't use "Contains" with property on another object
body: <p>Sorry for the bad title...This one is probably best explained with an example:</p>
  
  <pre><code>void Main()
  {
      IQueryable&lt;ClassA&gt; toLinkTo = context.ClassAs.Where(a =&gt; a.Name == "SomeName");
  
      var queryToExecute = context.ClassBs.Where(cb =&gt; toLinkTo.Select(ca =&gt; ca.Id).Contains(cb.Id));
  
      // This works.
      leafNodesWithExternalChildren.ToList();
  
      // This doesn't work.
      toLinkTo = new OtherClass(context).LinkedClassAs;
      leafNodesWithExternalChildren.ToList();
  }
  
  public class OtherClass
  {
      private MyContext m_Context;
  
      public OtherClass(MyContext ctx)
      {
          this.m_Context = ctx;
      }
  
      public IQueryable&lt;ClassA&gt; LinkedClassAs
      {
          get
          {
              // Same as toLinkTo as it was originally declared above.
              return this.m_Context.ClassAs.Where(a =&gt; a.Name == "SomeName");
          }
      }
  }
  </code></pre>
  
  <p>How come this works when <code>toLinkTo</code> is declared locally, but using the exact same <code>IQueryable</code> as a property on another object doesn't? The exception I get is:</p>
  
  <p><code>Unable to create a constant value of type 'ClassA'. Only primitive types ('such as Int32, String, and Guid') are supported.</code></p>
  
  <p>Thanks in advance.</p>