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 GetChildProducts : 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("Boots");
ProductCollection childProducts = departmentCategory.ChildProducts;
foreach (Product product in childProducts)
{
DisplayHelper.DisplayValue("DisplayName", product.DisplayName, Response);
}
}
protected void btnCS2009_Click(object sender, EventArgs e)
{
var catalogQuery = new CommerceQuery("Category");
catalogQuery.SearchCriteria.Model.Id = "Boots";
catalogQuery.SearchCriteria.Model.Properties["CatalogId"] = "Adventure Works Catalog";
//Get Child Categories
// Add Related Query Operation for child products
{
CommerceQueryRelatedItem queryChildProducts =
new CommerceQueryRelatedItem("ChildProducts", "Product");
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("ChildProducts") as CommerceRelationshipList;
if (childCategories != null)
foreach (var commerceRelationship in childCategories)
{
CommerceEntity childcategory = commerceRelationship.Target;
DisplayHelper.DisplayValue("DisplayName", childcategory.Properties["DisplayName"], Response);
}
}
}
}
Attached Source Code : ASPNet3346
