title: Nhibernate.Linq: Restricting query results with Where(Expression<Predicate<T>>)
body: <p>I query my Database using NHibernate. Now I need to restrict the data being selected using a Predicate. So far I found out (Google driven development at its best) that something like this is possible using Expressions and NHibernate.Linq.</p>
  
  <p>Here's what I tried:</p>
  
  <pre><code>public IList&lt;Bestellung&gt; GetAll(Predicate&lt;Order&gt; predicate)
  {
      Expression&lt;Func&lt;Order, bool&gt;&gt; restriction = x =&gt; predicate(x);
      ISession session = SessionService.GetSession();
      IList&lt;Order&gt; bestellungen = session.Query&lt;Order&gt;()
                          .Where(restriction).ToList();
      return bestellungen;
  }
  </code></pre>
  
  <p>This results in <strong>Unable to cast object of type 'NHibernate.Hql.Ast.HqlCast' to type 'NHibernate.Hql.Ast.HqlBooleanExpression'</strong>. Just a quickie to check where it sucks: Change the first line of the method body to </p>
  
  <pre><code>Expression&lt;Func&lt;Order, bool&gt;&gt; restriction = x =&gt; x.Id!=1;
  </code></pre>
  
  <p>with the stunning result that everything works fine.</p>
  
  <p>How can I get my Predicate executed in the expression?</p>