title: LINQ Entities build Query at Runtime 'The parameter is not in scope.' LinqKit
body: <p>I'm using LinqKit (http://www.albahari.com/nutshell/linqkit.aspx)</p>
  
  <p><strong>Is there a way to have the following code work without having to define a concrete class?</strong></p>
  
  <p>Trying to build a strongly typed dynamic query with LINQ to Entities.</p>
  
  <p>I'm getting <code>The parameter 'o' is not in scope.</code> error.</p>
  
  <p>in certain situations.</p>
  
  <pre><code>void Main()
  {   
      var lquery = from a in Foo select new { Bar = a.Baz }; // &lt;-- error like this
      //var lquery = from a in Foo select new stuff { Bar = a.Baz }; // &lt;-- here no error
      test("Case", lquery, o =&gt; o.Bar).Dump();
  }
  
  class stuff { public string Bar {get; set;} }
  
  IQueryable&lt;T&gt; test&lt;T&gt;(string val, IQueryable&lt;T&gt; qry, Expression&lt;Func&lt;T, string&gt;&gt; selector){
      var ex = selector.Expand();
      var b = from c in qry.AsExpandable()
              where ex.Invoke(c).Contains(val)
              select c;
      return b;
  }
  </code></pre>
  
  <p>It appears that when an anonymous class is used with <code>test()</code> this error is thrown when a concrete class <code>stuff</code> is used then no error. Is there a workaround which would allow an anonymous class to be used in this situation?</p>
  
  <p>I realize that this error might be LinkKit related but I don't have enough technical knowledge to dive in there...</p>