连接嵌套查询 NHibernate

发布于 2024-11-17 15:16:57 字数 651 浏览 0 评论 0原文

如何在 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; }
}

How do you do this query in NHibernate, with criteria or 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

Assume

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; }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蔚蓝源自深海 2024-11-24 15:16:57

内连接可以用子查询来描述。
达到 - 效果的东西

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

,您可以使用 QueryOver 的 WithSubquery 方法来内部联接到该子查询。
请参阅这篇文章有关 QueryOver API 的更多详细信息。

the inner join can be described by a subquery.
something to the effect of -

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

and you can use the WithSubquery method of QueryOver to inner join to that subquery.
see this article for further details on QueryOver API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文