title: Using LINQ Dynamic Query Library with Dictionary<string, object> and .AsQueryable()
body: <p>In one of my previous questions about using dynamically built up strings (where clauses) and using them in LINQ, I was guided towards the LINQ Dynamic Query Library <a href="http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx" rel="noreferrer">Dynamic LINQ</a>.</p>
  
  <p>The first issue was that it only applies to IQueryable, this however can be overcome by using the .AsQueryable() extension method on any IEnumerable.</p>
  
  <p>The problem I ran into was that Dynamic LINQ is looking for a Property called "CustomerID" (or whatever was passed in to the string predicate for dynamic linq) on my Dictionary.  Which obviously won't work since a Dictionary only has Keys and Values.</p>
  
  <p>So thinking I'm being clever, I created a class extending <code>: Dictionary&lt;string, object&gt;</code>, ICustomTypeDescriptor`.</p>
  
  <p>This allowed me to override <code>GetProperties()</code> on the type. Which is great.  I can now iterate the Dictionary keys and add them to a <code>PropertyDescriptorCollection</code> which gets returned.</p>
  
  <p>But then I ran into another problem.  Throughout the Dynamic LINQ library, they work with 'Expression instance' which only contains a Type. But for my <code>CustomTypeDescriptor</code> solution to work I need an actual instance of the Type, before I can apply <code>TypeDescriptor.GetProperties(instance, false)</code>.</p>
  
  <p>So getting to the actual question. Taking all the above information into account, how do I apply a custom where clause in string format "CustomerID=1234 AND Quantity >= 10000" to a LINQ query if the data is stored in a Dictionary with Key-Value pairs.</p>
  
  <p>My current solution is transforming the data into a <code>DataTable</code> and using the <code>.Select(query)</code> method.  Which works, but I'm interested in finding other solutions. Especially for benchmarking purposes.</p>
  
  <p>Any ideas?</p>