【问题标题】:Orchard CMS HQL Query Taxonomies : OR in WHERE conditionOrchard CMS HQL 查询分类法:OR 在 WHERE 条件下
【发布时间】:2018-05-02 16:45:28
【问题描述】:

我试图通过检查用户和页面之间的常用术语来过滤用户看到的页面。用户和页面都具有相同类型(“类别”)的分类字段,带有术语“标准”和“高级”。

如果用户的类别与页面的类别匹配,我想显示它,否则不显示。这适用于 PagePart 上的以下 IHqlQuery:

context.Query.Where(a => a.ContentPartRecord<TermsPartRecord>()
             .Property("Terms", "terms"), 
               x => x.InG("TermRecord.Id", ids));

其中 ids 是用户的术语 ID 列表。

除了上述条件之外,我还想显示没有附加条款的页面。这可以通过以下方式自行正常工作:

context.Query.Where(a => a.ContentPartRecord<TermsPartRecord>(),
            x => x.IsEmpty("Terms")

问题是当我尝试结合上述两个条件时。我试过了:

context.Query.Where(a => a.ContentPartRecord<TermsPartRecord>()
             .Property("Terms", "terms"), 
               p => p.Or(x => x.InG("TermRecord.Id", ids), y => y.IsEmpty("Terms")));

Or 语句中的第二个条件不起作用,因为查询已经在 Terms 集合中。

我也试过了:

context.Query.Where(a => a.ContentPartRecord<TermsPartRecord>()              
                p => p.Or(x => x.InG("Terms.TermRecord.Id", ids), y => y.IsEmpty("Terms")));

这里,第一个条件是错误的,因为我无法使用“Terms.TermRecord”访问条款列表的元素。这是就我的 Hql 能力而言。你有什么建议吗?提前谢谢你。

【问题讨论】:

    标签: orchardcms taxonomy


    【解决方案1】:

    恐怕我不是那么熟悉 Orchard 的查询 API,我总是发现它们很难用于更复杂的查询。您始终可以使用原始 HQL。

    select distinct civ.Id
    from Orchard.ContentManagement.Records.ContentItemVersionRecord civ
    join civ.ContentItemRecord ci
    join ci.ContentType ct
    left outer join ci.TermsPartRecord tpr
    left outer join tpr.Terms terms
    where ct.Name = 'Page' AND (terms.TermRecord.Id in (:ids) OR size(tpr.Terms) = 0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-15
      • 2014-05-30
      • 2018-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多