title: NHibernate QueryOver with sub-query and alias
body: <p>I'm struggling to convert the following (simplified) HQL to QueryOver:</p>
  
  <pre><code>select subscription
  from Subscription as subscription
  where not exists (
      from Shipment as shipment
      where shipment.Subscription = subscription
      and (shipment.DeliveryDate  = :deliveryDate)
  )
  </code></pre>
  
  <p>I've come this far:</p>
  
  <pre><code>Subscription subscription = null;
  
  Session.QueryOver(() =&gt; subscription)
      .Where(Subqueries.NotExists(QueryOver.Of&lt;Shipment&gt;()
          .Where(shipment =&gt; shipment.Subscription == subscription)
          .And(shipment=&gt; shipment.DeliveryDate == deliveryDate)
          .Select(shipment =&gt; shipment.Id).DetachedCriteria));
      .TransformUsing(new DistinctRootEntityResultTransformer());
  </code></pre>
  
  <p>The problem is that the above <code>Subqueries</code> and <code>Where</code> statement gives me the following (invalid) where clause:</p>
  
  <pre><code>where shipment.SubscriptionId is null
  </code></pre>
  
  <p>when what I want is:</p>
  
  <pre><code>where shipment.SubscriptionId = subscription.Id
  </code></pre>
  
  <p>So the alias and its row-level value isn't taken into account when constructing the SQL, instead its initial value <code>null</code> is used to compare to the <code>Shipment</code>'s <code>SubscriptionId</code>.</p>
  
  <h2>Update</h2>
  
  <p>With dotjoe's provided solution, I was able to write the <code>QueryOver</code> statement as follows:</p>
  
  <pre><code>Subscription subscription = null;
  
  Session.QueryOver(() =&gt; subscription)
      .WithSubquery.WhereNotExists(QueryOver.Of&lt;Shipment&gt;()
          .Where(shipment =&gt; shipment.Subscription.Id == subscription.Id)
          .And(shipment =&gt; shipment.DeliveryDate == deliveryDate)
          .Select(shipment =&gt; shipment.Id));
  </code></pre>