3/15/2009
Here is a simple piece of code to search for a product id based on the id of one of the product variants.
OperationContext currentInstance = OperationContext.CurrentInstance;
CatalogContext context = CommerceSiteContexts.Catalog[currentInstance.SiteName];
CatalogSearchOptions searchOptions = new CatalogSearchOptions();
searchOptions.PropertiesToReturn = "ProductId, VariantId";
CatalogSearch catalogSearch = context.GetCatalogSearch();
catalogSearch.CatalogNames = "Adventure Works Catalog";
catalogSearch.SqlWhereClause = "VariantId=15";
catalogSearch.SearchOptions = searchOptions;
int totalRecords = 0;
CatalogItemsDataSet catalogItems = catalogSearch.Search(out totalRecords);
This is useful code for administration tools, etc.