using System;
using System.Linq;
using Microsoft.Commerce.Common.MessageBuilders;
using Microsoft.Commerce.Contracts;
using Microsoft.Commerce.Contracts.Messages;
using Microsoft.CommerceServer.Catalog;
using Microsoft.CommerceServer.Runtime;
namespace ASPNet3346
{
public partial class GetChildCategories : System.Web.UI.Page
{
protected void btnCS2007_Click(object sender, EventArgs e)
{
ProductCatalog productCatalog = (ProductCatalog)CommerceContext.Current.CatalogSystem.GetCatalog("Adventure Works Catalog", "en-US");
// Get the root category.
Category departmentCategory = productCatalog.GetCategory("Departments");
CatalogItemsDataSet categories = departmentCategory.ChildCategories.DataSet;
foreach (CatalogItemsDataSet.CatalogItem category in categories.CatalogItems)
{
DisplayHelper.DisplayValue("DisplayName", category.DisplayName, Response);
}
}
protected void btnCS2009_Click(object sender, EventArgs e)
{
var catalogQuery = new CommerceQuery("Category");
catalogQuery.SearchCriteria.Model.Id = "Departments";
catalogQuery.SearchCriteria.Model.Properties["CatalogId"] = "Adventure Works Catalog";
//Get Child Categories
// Add Related Query Operation for child products
{
CommerceQueryRelatedItem queryChildProducts =
new CommerceQueryRelatedItem("ChildCategories", "Category");
//the relation name can ChildCategories,AncestorCategories,CanonicalCategories,ParentCategories,RelatedCategories , Ref MetadataDefinitions.xml
catalogQuery.RelatedOperations.Add(queryChildProducts);
}
CommerceResponse response = CommerceFoundationServiceAgent.Execute(catalogQuery);
// Handle Responses
CommerceQueryOperationResponse queryResponse = response.OperationResponses.Single() as CommerceQueryOperationResponse;
CommerceEntity productCatalog = queryResponse.CommerceEntities.SingleOrDefault();
var childCategories = productCatalog.GetPropertyValue("ChildCategories") as CommerceRelationshipList;
foreach (var commerceRelationship in childCategories)
{
CommerceEntity childcategory = commerceRelationship.Target;
DisplayHelper.DisplayValue("DisplayName", childcategory.Properties["DisplayName"], Response);
}
}
}
}
Attached Source Code : ASPNet3346
