title: IQueryable to List<T>
body: <p>I know IQueryable yields no result but just an expression builder, my problem is how can actually use it to execute query and return the set as List to be able to bind it on a grid.</p>
  
  <pre><code>  IQueryable query = _campaignManager.GetCampaign(filter, values);
  
    // this line returns error
    List&lt;Campaign&gt; campaigns = query.Cast&lt;Campaign&gt;().ToList();
  
    grdCampaigns.DataSource = campaigns;
    grdCampaigns.DataBind();
  </code></pre>
  
  <p>additional details: GetCampaign()</p>
  
  <pre><code>    public IQueryable GetCampaign(string filter, params object[] values)
      {
          string parameters = string.Empty;
          foreach (object obj in values)
          {
              parameters += obj.ToString() + ",";
          }
  
          parameters.Remove(parameters.Count() - 1, 1);
  
          var query = context.Campaigns.Where(filter, parameters)
             .Select("new(CampaignID,CampaignName)");
  
          return query;
      }
  </code></pre>
  
  <p>I'm using <a href="http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx" rel="nofollow">DynamicQueryable</a> for dynamic linq queries</p>
  
  <p>The .Select Extension method of the DynamicQueryable</p>
  
  <pre><code>     public static IQueryable Select(this IQueryable source, string selector, params object[] values)
      {
          if (source == null) throw new ArgumentNullException("source");
          if (selector == null) throw new ArgumentNullException("selector");
          LambdaExpression lambda = DynamicExpression.ParseLambda(source.ElementType, null, selector, values);
          return source.Provider.CreateQuery(
              Expression.Call(
                  typeof(Queryable), "Select",
                  new Type[] { source.ElementType, lambda.Body.Type },
                  source.Expression, Expression.Quote(lambda)));
      }
  </code></pre>
  
  <p>IQueryable .Where() extension</p>
  
  <pre><code>       public static IQueryable Where(this IQueryable source, string predicate, params object[] values)
      {
          if (source == null) throw new ArgumentNullException("source");
          if (predicate == null) throw new ArgumentNullException("predicate");
          LambdaExpression lambda = DynamicExpression.ParseLambda(source.ElementType, typeof(bool), predicate, values);
          return source.Provider.CreateQuery(
              Expression.Call(
                  typeof(Queryable), "Where",
                  new Type[] { source.ElementType },
                  source.Expression, Expression.Quote(lambda)));
      }
  </code></pre>
  
  <p>thanks...</p>