title: How to query Dynamic properties in NHibernate?
body: <p>I have this problem.
  I have a class like this:</p>
  
  <pre><code>public class WfStep
  {
      private readonly IDictionary properties = new Hashtable();
  
      public virtual Guid Id { get; private set; }
      public virtual string Name { get; set; }
      public virtual dynamic Properties { get { return new HashtableDynamicObject(properties); } }
  </code></pre>
  
  <p>and its mapping file like this:</p>
  
  <pre><code>&lt;class name="ConsoleApplication4.WfStep" table="WFSteps"&gt;
  
  &lt;id name="Id"&gt;
    &lt;generator class="guid"/&gt;
  &lt;/id&gt;
  &lt;property name="Name" /&gt;
  
  &lt;map name="Properties" table="WFSteps_Properties" access="field.lowercase"&gt;
    &lt;key column="StepId" /&gt;
    &lt;index column="PropertyName" type="System.String"/&gt;
    &lt;composite-element class="ConsoleApplication4.ValueItem, ConsoleApplication4"&gt;
      &lt;property name="Value" type="System.String"/&gt;
      &lt;property name="ValueType" type="System.String"/&gt;
    &lt;/composite-element&gt;
  &lt;/map&gt;   
  </code></pre>
  
  <p></p>
  
  <p>This example is ported from: 
  <a href="http://ayende.com/Blog/archive/2011/03/08/support-dynamic-fields-with-nhibernate-and-.net-4.0.aspx" rel="nofollow">Ayende Support dynamic fields with NHibernate and .NET 4.0</a></p>
  
  <p>Then I save an object to the db like this:
  ie.</p>
  
  <pre><code>var step = new WfStep { Name = "John" };
  var property = new ValueItem() { Value = DateTime.Now, ValueType = "System.DateTime" };
  step.Properties["DateProperty"] = property ;
  
  Session.Save(step);
  </code></pre>
  
  <p>Now I want to return all the WFSteps that have DateProperty set to year 2010 ie.:</p>
  
  <pre><code>var Session.Query&lt;WfStep&gt;().Where(x=&gt;x.Properties.DateProperty.Year == 2010);
  </code></pre>
  
  <p>It throws an error: </p>
  
  <blockquote>
    <p>An expression tree may not contain a dynamic operation</p>
  </blockquote>
  
  <p>How can I query this type of class that has Dynamic properties.?    </p>