2016-08-18 26 views
0

在Query Analyzer我能執行以下查詢產生我想要的結果:Sitecore的查詢,其中場是自

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

當我試圖在我的Department模型中使用玻璃映射以下Sitecore的查詢我沒有得到任何結果。

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

出於測試目的,我從上面返回所有ActionArticle S上的查詢中刪除and @Department='{38c76731-f18a-4d29-9d52-33fdb3329881}'

最終我希望能夠在查詢中引用當前的Department模型。沿此線的東西:

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

當然this的是不是在上述背景下可用的,所以我在虧損...

這是可能的,如果是我會怎樣實現這樣的事情?

+2

可能通過使用流暢的映射和委託,但*危險* *危險*任何使用Sitecore查詢,更不用說遞歸Sitecore查詢。這將會表現糟糕,特別是在負載下。你可以用搜索索引來做到這一點嗎? – techphoria414

回答

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