Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

HomeDev guideRecipesAPI Reference
Dev guideUser GuidesLegal TermsNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Fields selection

Select the expected fields that are returned from the response.

👍

Beta

The Optimizely Graph .NET Client is in beta. Contact your Customer Success Manager for information.

Single object fields

The Field and Fields methods are used for selecting properties of data objects. You can select your expected fields for response by calling multiple Field or Fields methods, for example:

var query = queryBuilder
.ForType<MyDocument>()
  .Fields(x=>x.Property1, x=> x.Property2)
  .Field(x=>x.Property3)
.ToQuery()
.BuildQueries();

IEnumerable fields

For IEnumerable<T> field type where T is a complex type, please use a method named NestedFields(). The difference of NestedFields is that, you first select the IEnumerable field then select the properties in type T.

var query = queryBuilder
.ForType<Content>()
  .NestedFields(x=>x.ExisingLanguages, f=> f.Name, f=> f.DisplayName)
  .Field(x=>x.Property3)
.BuildQueries();

In the precedeing example, you would select the Name and DisplayName properties of the Language class, specified by the ExistingLanguages property, which is of type IEnumerable<Language>.

Another way to achieve this is as the following:

You can use all properties of type T when select, filter, or facet using a simple block of code. Ensure that the method name equals with property name.

public static class CmsModelsExtension  
{  
      ...  
     public static ContentLanguageModel ExistingLanguages(this Content myprop)  
     {  
         return null;  
     }  
}  
// now you want to select properties in ExistingLanguages field, just use method ExistingLanguages() 
// instead of property ExistingLanguages :  
query.Fields(x=> x.ExistingLanguages().Name, x.ExistingLanguages().DisplayName)  
//filters  
query.Where(x=> x.ExistingLanguages().Name.StartWith("e"))  
//facets  
query.Facet(x=> x.ExistingLanguages().Name.FacetLimit(10))

See Tool tips: Optimizely Graph Client Tool and how to leverage CMS data models to build query blog for more information.

System fields

Optimizely Graph exposes the following system fields that can be selected using the following methods:

  • _deletedGetDeleted()
  • _idGetId()
  • _modifiedGetModified
  • _scoreGetScore()
var query = queryBuilder
.ForType<MyDocument>()
  .Fields(x=>x.Property1, x=> x.Property2)
  .GetScore()
  .GetId()
  .GetModified()
  .GetDeleted()
.ToQuery()
.BuildQueries();

If you are using Optimizely's generation tool, these system fields are not generated to your model class by default. You need to add them manually.