|
/// <summary>
/// Extends the ProductCatalog Entity
/// </summary>
/// <param name="catalogContext"></param>
internal void ExtendCatalogEntity(CatalogContext catalogContext)
{
// Create the property
CatalogProperty property = catalogContext.CreateProperty("VendorId",
CatalogDataType.String, 25);
// Add the property to the ExtensibleEntityType.ProductCatalog entity
catalogContext.AddPropertyToEntity(ExtensibleEntityType.ProductCatalog,
"VendorId");
// Get the properties added to the ExtensibleEntityType.ProductCatalog entity
CatalogPropertiesDataSet extendedProperties =
catalogContext.GetEntityProperties(ExtensibleEntityType.ProductCatalog);
// Iterate through all the extended properties
foreach(CatalogPropertiesDataSet.CatalogProperty extendedProperty in
extendedProperties.CatalogProperties)
{
string propertyName = extendedProperty.PropertyName;
}
// Now assign a value to the VendorId
ProductCatalog productCatalog = catalogContext.GetCatalog("My Catalog");
productCatalog["VendorId"] = "My Vendor";
// You can also use the Information property to do the same thing
// productCatalog.Information.Catalogs[0]["VendorId"] = "My Vendor";
// save the changes
productCatalog.Save();
string vendorId = null;
// Access the value of the "VendorId" property
// Validate that "VendorId" property has been added to the ProductCatalog
// entity and its value is not null
if ( productCatalog.HasProperty("VendorId")
&& !productCatalog.IsPropertyNull("VendorId"))
{
vendorId = (string)productCatalog["VendorId"];
// vendorId = (string)productCatalog.Information.Catalogs[0]["VendorId"];
}
// Remove the property from the ProductCatalog entity
catalogContext.RemovePropertyFromEntity(ExtensibleEntityType.ProductCatalog,
"VendorId");
} |