I am trying to convert the following (simplified) HQL to QueryOver:
select subscription from Subscription as subscription where not exists ( from Shipment as shipment where shipment.Subscription = subscription and (shipment.DeliveryDate = :deliveryDate) )
I went so far:
Subscription subscription = null; Session.QueryOver(() => subscription) .Where(Subqueries.NotExists(QueryOver.Of<Shipment>() .Where(shipment => shipment.Subscription == subscription) .And(shipment=> shipment.DeliveryDate == deliveryDate) .Select(shipment => shipment.Id).DetachedCriteria)); .TransformUsing(new DistinctRootEntityResultTransformer());
The problem is that the above Subqueries and Where statements provide me with the following (invalid) where clause:
where shipment.SubscriptionId is null
when I want:
where shipment.SubscriptionId = subscription.Id
Thus, the alias and its row level value are not taken into account when building SQL; instead, its initial null value is used to compare with the Shipment SubscriptionId .
Update
Using the solution provided by dotjoe, I was able to write the QueryOver as follows:
Subscription subscription = null; Session.QueryOver(() => subscription) .WithSubquery.WhereNotExists(QueryOver.Of<Shipment>() .Where(shipment => shipment.Subscription.Id == subscription.Id) .And(shipment => shipment.DeliveryDate == deliveryDate) .Select(shipment => shipment.Id));
source share