title: NHibernate Lambda expressions - are they turned into SQL
body: <p>I'm a bit of a NHibernate newbie and Im taking on some code written by another developer. I want to find out how NHibernate converts lambda based criteria into SQL.</p>
  
  <p>I know in Linq to SQL using Lambda expressions on queries means that the whole thing is turned into an expression tree and then into SQL (where possible) by the Linq to SQL provider. This can be seen by doing DataContext.Log = Console.Out.</p>
  
  <p>But what about an NHibernate criteria expression where Linq to NHibernate isnt being used?</p>
  
  <p>The following namespaces are imported...</p>
  
  <pre><code>using NHibernate;
  using NHibernate.Criterion;
  using NHibernate.LambdaExtensions;
  </code></pre>
  
  <p>.. and the criteria code looks like this...</p>
  
  <pre><code>    return Session.CreateCriteria&lt;MyObjectType&gt;()
          .Add&lt;MyObjectType&gt;(x =&gt; x.Id == id)
          .UniqueResult&lt;MyObjectType&gt;();
  </code></pre>
  
  <p>Will this be turned into an SQL statement e.g.</p>
  
  <pre><code>Select distinct * from table where id = [param]
  </code></pre>
  
  <p>... or will the whole dataset be pulled into memory giving a List and then have the lambda expressions applied against the objects. e.g.</p>
  
  <pre><code>return List&lt;MyObject&gt;.Where(x =&gt; x.id = id)  [or something similar].
  </code></pre>
  
  <p>I', not sure if my importing NHibernate.LambdaExtensions provides a sort of translation into SQL.</p>