0

In the Query Analyzer I am able to execute the following query which produces my desired result:

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

When I attempt the following sitecore query using Glass Mapper in my Department model I get no results.

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

For testing purposes I've removed and @Department='{38c76731-f18a-4d29-9d52-33fdb3329881}' from the query above which returns all ActionArticles.

Ultimately I'd like to be able to reference the current Department model within the query. Something along the lines of this:

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

Of course this is not available in the above context, so I'm at a loss...

Is this possible and if so how would I go about achieving such a thing?

kjmagic13
  • 1,298
  • 8
  • 15
  • 2
    It may be possible through use of fluent mapping and delegates, but *danger* *danger* on any use of Sitecore Query, let alone recursive Sitecore queries. This is going to perform horribly, especially under load. Can you do this with a Search Index instead? – nickwesselman Aug 18 '16 at 16:01

1 Answers1

1

I am able to get my desired result with the following, but it doesn't seem to be the most efficient way.

// 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);
    }
}
kjmagic13
  • 1,298
  • 8
  • 15