CommerceQuery
This operation is used to query for existing commerce entities, related commerce entities, or relationships.
Note
When performing full text search it is good practice to include search keys in the description text of the object, or provide a search key property that lists all relevant search keys.
Class |
Description |
---|---|
CommerceOperation |
Base class of every operation.
PropertyDescription
ModelThis property represents the commerce entity of the operation. An example is a query for Product.
RelatedOperationsThis list represents commerce entities that are related to the Model. An example is a query for reviews of a Product.
|
CommerceQueryOperation |
This is the concrete query operation class.
PropertyDescription
SearchCriteriaThis property specifies the search clause of the query as well as paging and sorting options.
|
CommerceRelatedOperation (Abstract) |
Base class for every type of supported related item.
PropertyDescription
ModelThis property represents the related business type the query is for.
RelationshipNameThis indicates which collection the commerce entity belongs to. An example is the Review collection of the Product.
SearchCriteriaThis property identifies the search information used to locate the related commerce entities. If none are specified, the implicit relationship with the parent is assumed. An example is a Query for a Product where the Id is “Product_1”. If reviews are requested, reviews related to Product_1 are returned.
RelatedOperationsThis property provides the ability to specify child relationships of the commerce entity.
|
CommerceQueryRelatedItem |
This class indicates a search for existing related commerce entities. |
CommerceQueryRelationship |
This class indicates relationships are being searched. |
CommerceQueryOptions |
Options specific to query operation.
PropertyDescription
IsRecursiveWhen True it indicates that child commerce entities are also returned. For example, when querying for all products of a specified category, setting IsRecursive to true also returns products found under child categories of the given category. This is not supported for every type of query and is defined as part of the API documentation. This option should be used with care as this could impact performance.
|
CommerceBasketQueryOptions |
Options specific to a basket query operation.
PropertyDescription
RefreshBasketWhen False it indicates that the Commerce Server basket pipeline(s) should not be executed when retrieving the Basket. The default behavior is that the Commerce Server basket pipeline will be executed. This option only applies to commerce entities that map to a Commerce Server OrderGroup.
|
Restrictions
If the SearchCriteria type is not supported, the system will throw an exception. If you query relationships with invalid relationship names, the result of the query for this relationship will be <null>.
Response
Running a CommerceQueryOperation request creates a CommerceQueryOperationResponse.
Class |
Description |
---|---|
CommerceOperationResponse |
Base class for every operation.
PropertyDescription
FirstItemIndexThis property represents the (0 based) index of the first item returned in the CommerceEntities list.
TotalItemCountThis property represents the total number of items that exists out there for the given search criteria. This value is returned only if the ReturnTotalItemCount of the SearchCriteria has been set to true in the request.
|
CommerceQueryOperationResponse |
Response of a CommerceQueryOperation.
PropertyDescription
CommerceEntitiesThis list represents the commerce entities returned as part of the CommerceQueryOperation.
NOTE:Related items of any given commerce entity are contained in the Properties collection. The key represents the relationship name while the resulting collection is encapsulated in a CommerceRelationship object. The CommerceRelationship also contains FirstItemIndex and TotalItemCount properties that allow related items to be paged. |
CommerceQuery<> Generic Class
The CommerceQuery<> generic class constructs a CommerceQueryOperation operation request.
Class |
Description |
---|---|
CommerceQuery<TItem, TSearch, TOptions> |
Generic class that creates a CommerceQueryOperation request.
PropertyDescription
TItemThis item represents the commerce entity type (i.e. the Model) of the query operation.
TSearchThis item represents the SearcCriteria type to be applied to locate the commerce entity.
TOptionsThis item represents the Options type of the query operation.
|
CommerceQuery<TItem, TSearch> |
Generic class that creates a CommerceQueryOperation request.
PropertyDescription
TItemThis item represents the commerce entity type (i.e. the Model) of the query operation. The QueryOptions is defaulted to CommerceQueryOptionsBuilder which represents the default CommerceQueryOptions message.
TSearchThis item represents the SearcCriteria type to be applied to locate the commerce entity.
|
CommerceQuery<TItem> |
Generic class that creates a CommerceQueryOperation request.
PropertyDescription
TItemProvides a short form that default the TSearch of the derived CommerceQuery<> to a CommerceModelSearch on TItem. The CommonSearchCriteria is defaulted to COmmerceModelSearch of the model represented by TItem.
|
CommerceQueryRelatedItem<TItem> |
Generic class that extends the query to related commerce entities.
PropertyDescription
TItemThis item represents the related commerce entity type.
|
CommerceQueryRelationship<TItem,TRelationship> |
Generic class that extends the query to relationships of a commerce entity.
PropertyDescription
TItemThis item represents the commerce entity of the relationship.
TRelationshipThis item represents the data type of the relationship.
|
CommerceOptionsBuilder<TOptions> |
Base builder class for operation Options
PropertyDescription
TOptionsThis item represents the type of CommerceDeleteOptions to be sent.
|
CommerceQueryOptionsBuilder |
Class that builds QueryOptions for a query operation. |
CommerceBasketQueryOptionsBuilder |
Class that builds CommerceBasketQueryOptions for a query operation that targets a commerce entity that maps to a Commerce Server OrderGroup. |
Example
The following example queries for all defined cross-sell relationships of a specific product.
var productQuery = new CommerceQuery<CommerceEntity>("Product");
productQuery.SearchCriteria.Model.Properties["CatalogId"] = "Adventure Works Catalog";
productQuery.SearchCriteria.Model.Id = "AW200-12";
productQuery.Model.Properties.Add("Id");
productQuery.Model.Properties.Add("DisplayName");
productQuery.Model.Properties.Add("Description");
productQuery.Model.Properties.Add("ListPrice");
{
var queryVariants = new CommerceQueryRelatedItem<CommerceEntity>("Variants", "Variant");
queryVariants.SearchCriteria.SortProperties = new List<CommerceSortProperty>();
queryVariants.SearchCriteria.SortProperties.Add(new CommerceSortProperty("Variant", "ProductColor", SortDirection.Ascending));
queryVariants.SearchCriteria.FirstItemIndex = 0;
queryVariants.SearchCriteria.ReturnTotalItemCount = true;
queryVariants.Model.Properties.Add("Id");
queryVariants.Model.Properties.Add("VariantCode");
queryVariants.Model.Properties.Add("ProductColor");
productQuery.RelatedOperations.Add(queryVariants);
}
CommerceQueryOperationResponse response =
OperationService.ProcessRequest(base.GetCurrentRequestContext(), productQuery.ToRequest()).OperationResponses[0]
as CommerceQueryOperationResponse;