gpt4 book ai didi

c# - 带有子查询和别名的 NHibernate QueryOver

转载 作者:太空狗 更新时间:2023-10-30 01:25:05 25 4
gpt4 key购买 nike

我正在努力将以下(简化的)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());

问题是上面的 SubqueriesWhere 语句给了我以下(无效的)where 子句:

where shipment.SubscriptionId is null

当我想要的是:

where shipment.SubscriptionId = subscription.Id

因此在构造 SQL 时不考虑别名及其行级值,而是使用其初始值 nullShipment 进行比较' s 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));

最佳答案

尝试

.Where(shipment => shipment.Subscription.Id == subscription.Id)

关于c# - 带有子查询和别名的 NHibernate QueryOver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7742453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com