加入嵌套查询 NHibernate

3
您好,您想在 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; }
}
1个回答

0

内连接可以通过子查询来描述。
类似于以下内容 -

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

你可以使用QueryOver的WithSubquery方法来内连接到子查询。 请参阅此文章以获取有关QueryOver API的更多详细信息。


但是如何使用WithSubquery进行连接操作呢? - FrankF
找不到使用 WithSubquery 进行连接的方法。 - Alexey Zimarev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接