title: How can I use a dynamically typed IQueryable?
body: <p>I have an ASP.NET app that uses Kendo Grids to show data. I am trying to create a way for users to create their own Grids dynamically to show whatever data in the database they want (within limits, of course).</p>
  
  <p>My problem arises because I don't know at compile time what table the user will want to query on. For similar, but static, grids I use the System.Linq.IQueryable object, like so:</p>
  
  <pre><code>IQueryable&lt;v_InvCountLine&gt; query;
  query = from w in dc.v_InvCountLines
              where w.BatchNum == batchNum &amp;&amp; w.StoreRoom == storeroom &amp;&amp; w.Serialized == 0
              select w;
  
  //where v_InvCountLines is the name of a database table(view).
  </code></pre>
  
  <p>I want to accomplish a similar thing, but querying a table determined by a string passed in from the user.</p>
  
  <p>From <a href="https://stackoverflow.com/questions/955331/creating-a-generic-object-based-on-a-type-variable">this question</a> I've managed to create such an object, but it is of type object and so it doesn't have access to any of the methods I need to actually do the work.</p>
  
  <pre><code>//WOLinq is the name of a database table
  Type objectType = Type.GetType("WOLinq");
  Type type = typeof(IQueryable&lt;&gt;).MakeGenericType(objectType);
  object query = Activator.CreateInstance(type);
  </code></pre>
  
  <p>Is there a way to cast <code>query</code> down to it's actual type, or some other way to dynamically select a table to query with IQueryable&lt;>?</p>