我正在努力将以下(简化的) HQL转换为QueryOver:
select subscription
from Subscription as subscription
where not exists (
from Shipment as shipment
where shipment.Subscription = subscription
and (shipment.DeliveryDate = :deliveryDate)
)我已经走了这么远了:
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());问题是上面的Subqueries和Where语句给了我以下(无效的) where子句:
where shipment.SubscriptionId is null当我想要的是:
where shipment.SubscriptionId = subscription.Id因此,在构造SQL时不考虑别名及其行级值,而是使用它的初始值null与Shipment的SubscriptionId进行比较。
更新
使用dotjoe提供的解决方案,我能够按如下方式编写QueryOver语句:
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));发布于 2011-10-12 23:27:18
试一试
.Where(shipment => shipment.Subscription.Id == subscription.Id)https://stackoverflow.com/questions/7742453
复制相似问题