Query filters
This is not the recommended way of creating queries. Use LINQ instead.
Query object
The querying client requires a query to be defined. The query supports the following parameters:
Parameter |
Description |
---|---|
|
The type of filter to be invoked. |
|
The number of entities to be skipped. |
|
The number of entities to be retrieved. |
|
The load configuration to be applied. |
|
The sorting options to be applied. |
IdQueryFilter
Filters on the entity ids.
Parameter 'Value' should be used to query on a single id.
var query = new Query
{
Filter = new IdQueryFilter { Value = entityId }
};
The parameter 'Values' should be used to filter on multiple ids.
var query = new Query
{
Filter = new IdQueryFilter {
Values = new List<long>() { assetId, assetTypeId }
}
};
The supported comparison operators are:
-
Equals
-
NotEquals
The Equals comparison operator is used by default when no operator is specified.
DefinitionQueryFilter
Provides the ability to filter on an entity definition.
The 'Name' parameter should be used to filter on the name of a single entity definition.
var query = new Query
{
Filter = new DefinitionQueryFilter { Name = "M.Asset" }
};
The 'Names' parameter should be used to filter on multiple entity definition names.
var query = new Query
{
Filter = new DefinitionQueryFilter {
Names = new string[] { "M.Asset", "M.Fragment" }
}
};
It is also possible to filter on the entity definition by id, using the 'Id' parameter.
var query = new Query
{
Filter = new DefinitionQueryFilter {
Id = assetDefinitionId
}
};
The supported comparison operators are:
-
Equals
-
NotEquals
The Equals comparison operator is used by default when no operator is specified.
PropertyQueryFilter
Filters on entities based on one or more property values. The specified data type will determine the type of the value and the valid comparison operators.
Note that the datatype string can be used to query on datasource properties.
The 'Value' parameter should be used when filtering on a single value.
var query = new Query
{
Filter = new PropertyQueryFilter {
Property = "Title",
Value = "Logo",
DataType = FilterDataType.String
}
};
Filtering on multiple values is possible by using the 'Values' parameter. The values will be interpreted using an OR operator. This concludes that any entity with the given property, matching one of the specified values will be returned.
var query = new Query
{
Filter = new PropertyQueryFilter {
Property = "Title",
Values = new string[] { "Logo", "Sitecore Content Hub" },
DataType = FilterDataType.String
}
};
A culture can be specified to filter in using the 'Culture' parameter. This only applies for multilingual properties.
var query = new Query
{
Filter = new PropertyQueryFilter {
Property = "Description",
Value = "Sitecore Content Hub Logo",
DataType = FilterDataType.String,
Culture = new CultureInfo("en-US")
}
};
The supported comparison operators depend on the specified data type. An exception will be thrown when the comparison operator is not valid in the given context.
RelationQueryFilter
Filters on entities that have a relation to a specified entity using one or more parent ids. The name of the relation needs to be specified in the 'Relation' parameter.
The 'ParentId' parameter should be specified when filtering on a single relation entity.
var query = new Query
{
Filter = new RelationQueryFilter {
Relation = "AssetTypeToAsset",
ParentId = assetTypeId
}
};
Multiple parent ids can be specified using the 'ParentIds' parameter. The ids will be interpreted using an OR operator. This concludes that any entity with the given property, matching one of the specified values will be returned.
var query = new Query
{
Filter = new RelationQueryFilter {
Relation = "AssetTypeToAsset",
ParentIds = new long[] { logoAssetTypeId, mediaAssetTypeId }
}
};
CreatedByQueryFilter
Filters on entities created by one or more users.
Filters can be applied by specifying one or more Ids, using either the 'Id' or 'Ids' property.
var query = new Query
{
Filter = new CreatedByQueryFilter()
{
Id = userId
}
};
When specifying multiple ids using the 'Ids' parameter, all entities that were created by one of the given user id's will be returned.
var query = new Query
{
Filter = new CreatedByQueryFilter()
{
Ids = new long[] { demoUserId, trainingUserId }
}
};
It is also possible to specify one or more usernames using the 'Username' or 'Usernames' property.
var query = new Query
{
Filter = new CreatedByQueryFilter()
{
Username = "M.Demo.User"
}
};
When specifying multiple usernames, any entity created by one of the given users will be returned.
var query = new Query
{
Filter = new CreatedByQueryFilter()
{
Usernames = new string[] { "M.Demo.User", "M.Training.User" }
}
};
The supported comparison operators are:
-
Equals
-
NotEquals
The Equals comparison operator is used by default when no operator is specified.
CompositeQueryFilter
Allows combination of different query filters using the 'AND', 'OR' combine operators. The query filters can be specified using the 'Children' parameter of the composite query filter. The combine method operator can be specified using the 'CombineMethod' parameter.
var query = new Query
{
Filter = new CompositeQueryFilter()
{
Children = new QueryFilter[] {
new RelationQueryFilter
{
Relation = "AssetTypeToAsset",
ParentId = logoAssetTypeId
},
new PropertyQueryFilter {
Property = "Title",
Values = new string[] { "Logo", "Sitecore Content Hub" },
DataType = FilterDataType.String
}
},
CombineMethod = CompositeFilterOperator.Or
}
};
Query load configuration
Load configurations can be set on the LoadConfiguration
of the Query
object.
See Load configurations for more information.
EntityLoadOptions
from the older SDK has been deprecated, use LoadConfiguration
instead.