gpt4 book ai didi

nhibernate - 加入嵌套查询 NHibernate

转载 作者:行者123 更新时间:2023-12-03 16:44:59 25 4
gpt4 key购买 nike

如何在 NHibernate 中使用条件或 QueryOver 执行此查询?

select r.relationshipidentifier, r.publicrelationshipid
from relationship r
inner join (
select max(asofdate) as asofdate, s.relationshipidentifier
from relationship s
group by s.relationshipidentifier
) m
on r.asofdate = m.asofdate and r.relationshipidentifier = m.relationshipidentifier

假设

public class Relationship {
public virtual Guid Id { get; set; }
public virtual DateTime AsOfDate { get; set; }
public virtual Guid RelationshipIdentifier { get; set; }
public virtual Guid PublicRelationshpId { get; set; }
}

最佳答案

内连接可以用子查询来描述。
效果是-

QueryOver.Of<Relationship>()
.SelectList(list =>
list.SelectMax(r => r.AsOfDate),
list.GroupProperty(r=> r.RelationshipIdentifier)
)

并且您可以使用 QueryOver 的 WithSubquery 方法来内部连接到该子查询。见this article有关 QueryOver API 的更多详细信息。

关于nhibernate - 加入嵌套查询 NHibernate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6523567/

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