title: Converting a LINQ dynamic query to IQueryable in Entity Framework
body: <p>I am trying to convert a LINQ query that joins two tables to <code>IQueryable</code> type in Entity Framework so I can further apply filter expression on it. </p>
  
  <p>Here's the code:</p>
  
  <pre><code>IQueryable&lt;Bill_Joined_V1&gt; bills = 
       (from primary in _billEntity.BillTable
        join secondary in _billEntity.BillInfoTable on primary.BillID equals secondary.BillID
        orderby primary.BillID
        select new
                  {
                      primary.BillID,
                      primary.CustomerID,
                      secondary.Name,
                      secondary.Value
                  }).AsQueryable&lt;Bill_Joined_V1&gt;().Where(FilterExp);
  </code></pre>
  
  <p>The entity classes are as follows:</p>
  
  <pre><code>public class Bill_V1
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public Guid BillID { get; set; }
  
      public string BillTypeID { get; set; }
      public Guid CustomerID { get; set; }
      public Guid UserID { get; set; }
  
      [ForeignKey("UserID")]
      public virtual User_V1 UserTable { get; set; }
  
      public double AmountDue { get; set; }
  }
  
  public class BillInfo_V1
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public long BillInfoID { get; set; }
  
      public Guid BillID { get; set; }
  
      [ForeignKey("BillID")]
      public virtual Bill_V1 BillTable { get; set; }
  
      public string Name { get; set; }
      public string Value { get; set; }
  }
  
  // Dummy bill record for query purpose
  public class Bill_Joined_V1
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public long BillRecID { get; set; }
  
      public Guid BillID { get; set; }
      [ForeignKey("BillID")]
      public virtual Bill_V1 BillTable { get; set; }
  
      public Guid CustomerID { get; set; }
      [ForeignKey("CustomerID")]
      public virtual Customer_V1 CustomerTable { get; set; }
  
      public string Name { get; set; }
      public string Value { get; set; }
  
  }
  </code></pre>
  
  <p>The code does not compile. It produces error message saying </p>
  
  <blockquote>
    <p>'System.Linq.IQueryable' does not contain a definition for 'AsQueryable' and the best extension method overload 'System.Linq.Queryable.AsQueryable(System.Collections.Generic.IEnumerable)' has some invalid arguments </p>
  </blockquote>
  
  <p>Is there a way to convert the LINQ query to <code>IQueryable</code> type without putting the query result to a physical table? How do I work around this? Thanks.</p>