HelloWorld
HelloWorld

Reputation: 3739

How to use PropertyCriteria on complex property?

I'm new to EPiSERVER. Currently trying to search for a page with a specific property set to a specific value.

I need the property CatalogEntryPoint (a ContentReference) to equal something. Here is the criterea:

        PropertyCriteria secCriteria = new PropertyCriteria();

        secCriteria.Condition = CompareCondition.Equal;
        secCriteria.Name = "CatalogEntryPoint.ID";
        secCriteria.Type = PropertyDataType.Number;
        secCriteria.Value = currentContent.ContentLink.ID.ToString();
        secCriteria.Required = true;

And here is an excerpt from the search index:

{
  "CatalogEntryPoint": {
    "$type": "EPiServer.Find.Cms.IndexableContentReference, EPiServer.Find.Cms",
    "ID$$number": 1073742170,
    "WorkID$$number": 0,
    "ProviderName$$string": "CatalogContent",
    "GetPublishedOrLatest$$bool": false,
    "IsExternalProvider$$bool": true,
    "___types": [
      "EPiServer.Find.Cms.IndexableContentReference",
      "EPiServer.Core.ContentReference",
      "System.Object",
      "System.IComparable",
      "EPiServer.Data.Entity.IReadOnly"
    ]
  },

It would seem that the CatalogEntryPoint.ID-notation does not work as I'm getting 0 results. How should I write it?

Upvotes: 1

Views: 444

Answers (1)

Andreas
Andreas

Reputation: 1355

The PropertyDataType has a ContentReference option. The following should work:

PropertyCriteria secCriteria = new PropertyCriteria();

secCriteria.Condition = CompareCondition.Equal;
secCriteria.Name = "CatalogEntryPoint";
secCriteria.Type = PropertyDataType.ContentReference;
secCriteria.Value = currentContent.ContentLink.ToString();
secCriteria.Required = true;

You could also just do ContentLink.ID.ToString(), the code ContentLink.ToString() preserves the content version I believe.

Upvotes: 2

Related Questions