다음을 통해 공유


How to Create a Property

A property describes a characteristic of a product or category, such as Name, Title, Color, and so on. A property can be used by multiple product definitions and category definitions and can be shared across catalogs. When you create a property, the property is added to the Commerce Server Core Systems database schema. For more information about properties, see What is a Property Definition?

To create a property

  • Create the properties needed in your catalog by using the CreateProperty method of the CatalogContext object.

    Dd451361.alert_caution(en-US,CS.90).gifImportant Note:

    Do not use the following characters in the property name: .,/"[]'.

Example

This example creates properties for a product in a catalog of CDs. It creates the properties Title, Runtime, Artist, and Label. It adds these properties to a product definition and saves the definition.

public static void CreateProperties(CatalogContext context)
{    
    // Create the properties for a CD in a catalog. 
    CatalogProperty title = context.CreateProperty("Title", CatalogDataType.String, 250);
    CatalogProperty runtime = context.CreateProperty("RunTime", CatalogDataType.Integer, 0);
    CatalogProperty artist = context.CreateProperty("Artist", CatalogDataType.String, 500);
    CatalogProperty label = context.CreateProperty("Label", CatalogDataType.String, 25);
           
    // Create a product definition.
    CatalogDefinition productDefinition = context.CreateDefinition("CD", CatalogDefinitionType.ProductDefinition);
            
    // Add the properties to the product definition and save the definition.
    productDefinition.AddProperty(title.Name, DefinitionPropertyType.NormalProperty);
    productDefinition.AddProperty(artist.Name, DefinitionPropertyType.NormalProperty);
    productDefinition.AddProperty(label.Name, DefinitionPropertyType.NormalProperty);
    productDefinition.AddProperty(runtime.Name, DefinitionPropertyType.NormalProperty);
    productDefinition.Save();
}

See Also

Other Resources

How to Create a CatalogContext Object

Managing Base Catalogs by Using the Catalog API