title: IQueryable Expression Translation
body: <p>I am creating an IQueryable that I want to use for a query passed to entity framework.  My repository does not expose queryable.  </p>
  
  <pre><code> var query = new List&lt;Entity&gt;().AsQueryable().Where(x =&gt; x.Property == "argument");
  </code></pre>
  
  <p>I have a method on my repository that will take in an IQueryable.</p>
  
  <p>How do I query my DbSet with the same queryable?  I am trying to extract the expression from the queryable to build a new expression for the dbset.  Here is what I have so far but it does not work:</p>
  
  <pre><code>public IDbSet&lt;TEntity&gt; DbSet { get; set; }
  
  public IEnumerable&lt;TEntity&gt; Find(IQueryable&lt;TEntity&gt; queryable)
  {
        var parameter = Expression.Parameter(typeof (TEntity));
        var body = queryable.Expression;
  
        var lambda = Expression.Lambda&lt;Func&lt;TEntity, bool&gt;&gt;(body, parameter);
        var result =  DbSet.Where(lambda);
        return null;
  }
  </code></pre>
  
  <p>The code fails when I try and create the lambda with the following error:
  Expression of type 'System.Linq.IQueryable`1[MyTEntity]' cannot be used for return type 'System.Boolean'</p>
  
  <p>I'm clearly not building the expression correctly, what am I missing?  Is there an easier way to do what I'm trying to accomplish?</p>
  
  <p>Also I've seen some examples that show an Expression should have a parameters property.  But no matter what type of expression type I cast to, and this one is ConstantExpression, I don't see a parameters property from the IQueryable.Expression.</p>