Sitecore查询字段为self

时间:2016-08-18 15:32:19

标签: asp.net-mvc sitecore sitecore8 sitecore-mvc glass-mapper

在查询分析器中,我能够执行以下查询,产生我想要的结果:

select * from /sitecore/content/Home//*[@@templatekey='action' and @Department='{38c76731-f18a-4d29-9d52-33fdb3329881}']

当我在Department模型中使用Glass Mapper尝试以下sitecore查询时,我没有得到任何结果。

[SitecoreQuery("/sitecore/content/Home//*[@@templatekey='action' and @Department='{38c76731-f18a-4d29-9d52-33fdb3329881}']", IsRelative = false)]
public virtual IEnumerable<ActionArticle> TestServices { get; set; }

出于测试目的,我已从上面的查询中删除and @Department='{38c76731-f18a-4d29-9d52-33fdb3329881}',该查询将返回所有ActionArticle

最终,我希望能够在查询中引用当前的Department模型。有点像这样:

[SitecoreQuery("/sitecore/content/Home//*[@@templatekey='action' and @Department='"+ this.Id +"']", IsRelative = false)]
public virtual IEnumerable<ActionArticle> TestServices { get; set; }

当然this在上述情况下不可用,所以我不知所措......

这是否可能,如果是这样,我将如何实现这样的目标呢?

1 个答案:

答案 0 :(得分:1)

我能够通过以下方式获得我想要的结果,但它似乎不是最有效的方式。

// ActionArticle model

[SitecoreField("Department")]
public virtual Guid Department { get; set; }

// Department model

[SitecoreId]
public virtual Guid Id { get; set; }

[SitecoreQuery("/sitecore/content/Home//*[@@templatekey='action']", IsRelative = false)]
private IEnumerable<ActionArticle> AllServices { get; set; }

public virtual IEnumerable<ActionArticle> Services
{
    get
    {
        return this.AllServices.Where(x => x.Department == this.Id);
    }
}