【问题标题】:NHibernate QueryOver with SubQuery in where with orNHibernate QueryOver with SubQuery in where with or
【发布时间】:2011-10-09 17:12:03
【问题描述】:

我需要在 NHibernate 中使用 QueryOver 执行以下 SQL:

select *
from Post post
where post.User.Id = 1
or post.Level in (1, 2, 3)
or (select Id
    from SubPost sub
    where sub.Post = post
    and sub.User.Id = 1) != null

我现在不知道如何使用 QueryOver 做到这一点。我的问题是我必须如何声明子查询以及如何使用or 条件添加它。我希望,有人可以给我一个提示。谢谢。

最好的问候,托马斯

【问题讨论】:

    标签: c# nhibernate subquery queryover


    【解决方案1】:

    试试这个

    Post p = null;
    SubPost s = null;
    return session.QueryOver<Post>( () => p)
               .where( () => p.User.Id == 1)
               .Where( () => p.Level == 1 || p.Level == 2 || p.Lvel ==3 )
               .JoinAlias( () => s.Post , () => p)
               .Where( () => p.User.Id == 1)
               .List<Post>();
    

    我不确定 JoinAlias 之后的第二个位置,但试试看

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-04
      • 2011-07-21
      • 2013-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多