Fields selection
Select the expected fields that are returned from the response.
Single object fields
TheField andFields methods are used for selecting properties of data objects. You can select your expected fields for response by calling multipleField orFields methods, for example:
var query = queryBuilder.ForType<MyDocument>() .Fields(x=>x.Property1, x=> x.Property2) .Field(x=>x.Property3).ToQuery().BuildQueries();IEnumerable fields
ForIEnumerable<T> field type whereT is a complex type, please use a method namedNestedFields(). The difference ofNestedFields is that, you first select theIEnumerable field then select the properties in typeT.
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 theName andDisplayName properties of theLanguage class, specified by theExistingLanguages property, which is of typeIEnumerable<Language>.
Another way to achieve this is as the following:
You can use all properties of typeT 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))SeeTool 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:
_deleted–GetDeleted()_id–GetId()_modified–GetModified_score–GetScore()
var query = queryBuilder.ForType<MyDocument>() .Fields(x=>x.Property1, x=> x.Property2) .GetScore() .GetId() .GetModified() .GetDeleted().ToQuery().BuildQueries();If you are using Optimizely'sgeneration tool, these system fields are not generated to your model class by default. You need to add them manually.
Updated 23 days ago
