nHibernate 用于选择具有空子集合的所有实体的标准

发布于 2024-09-01 07:18:14 字数 845 浏览 1 评论 0原文

我很难编写一个标准来选择具有空子集合或空孙集合的所有实体。我可以将这些作为单独的标准来执行,但我无法将其合并为单个标准。

类结构:

public class Component
    {
        public IList<Version> Versions { get; set; }
    }

    public class Version
    {
        public IList<SubscribeEvent> SubscribedEvents { get; set; }
        public IList<PublishEvent> PublishedEvent { get; set; }
    }

这不起作用:

return session
                .CreateCriteria<Component>("c")
                .CreateCriteria("Versions", "v")
                .Add(Restrictions.Or(Restrictions.IsEmpty("c.Versions"), Restrictions.And(Restrictions.IsEmpty("v.PublishedEvents"),
                                                                                        Restrictions.IsEmpty("v.SubscribedEvents"))))
                .SetCacheable(true);

I'm having difficulty writing a Criteria to select all entities with empty child collections or empty grand-child collections. I can do these as separate Criteria but I'm having trouble combining into a single Criteria.

class structure:

public class Component
    {
        public IList<Version> Versions { get; set; }
    }

    public class Version
    {
        public IList<SubscribeEvent> SubscribedEvents { get; set; }
        public IList<PublishEvent> PublishedEvent { get; set; }
    }

This does not work:

return session
                .CreateCriteria<Component>("c")
                .CreateCriteria("Versions", "v")
                .Add(Restrictions.Or(Restrictions.IsEmpty("c.Versions"), Restrictions.And(Restrictions.IsEmpty("v.PublishedEvents"),
                                                                                        Restrictions.IsEmpty("v.SubscribedEvents"))))
                .SetCacheable(true);

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

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

发布评论

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

评论(1

潦草背影 2024-09-08 07:18:15

我已经设法找到了一个解决方案,不确定它是否是最好的(我应该购买 NH 分析器)

return session
            .CreateCriteria<Component>("c")
            .CreateAlias("Versions", "v", JoinType.LeftOuterJoin)
            .Add(Restrictions.Or(Restrictions.IsEmpty("c.Versions"),
                                 Restrictions.And(Restrictions.IsEmpty("v.SubscribedEvents"),
                                                  Restrictions.IsEmpty("v.PublishedEvents"))))
            .SetCacheable(true);

I've managed to work out a solution, not sure if it is the best (I should buy NH profiler)

return session
            .CreateCriteria<Component>("c")
            .CreateAlias("Versions", "v", JoinType.LeftOuterJoin)
            .Add(Restrictions.Or(Restrictions.IsEmpty("c.Versions"),
                                 Restrictions.And(Restrictions.IsEmpty("v.SubscribedEvents"),
                                                  Restrictions.IsEmpty("v.PublishedEvents"))))
            .SetCacheable(true);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文